Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flux

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flux - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

flow/include/abstractMethod.js

2

index.js

@@ -10,2 +10,2 @@ /**

module.exports.Dispatcher = require('./lib/Dispatcher')
module.exports.Dispatcher = require('./lib/Dispatcher');

@@ -1,3 +0,3 @@

/*
* Copyright (c) 2014, Facebook, Inc.
/**
* Copyright (c) 2014-2015, Facebook, Inc.
* All rights reserved.

@@ -10,10 +10,14 @@ *

* @providesModule Dispatcher
* @typechecks
*
* @preventMunge
*/
"use strict";
'use strict';
var invariant = require('./invariant');
exports.__esModule = true;
var _lastID = 1;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var invariant = require('fbjs/lib/invariant');
var _prefix = 'ID_';

@@ -68,3 +72,3 @@

*
* CountryStore.dispatchToken = flightDispatcher.register(function(payload) {
* CountryStore.dispatchToken = flightDispatcher.register(function(payload) {
* if (payload.actionType === 'country-update') {

@@ -97,2 +101,3 @@ * CountryStore.country = payload.selectedCountry;

* case 'country-update':
* case 'city-update':
* flightDispatcher.waitFor([CityStore.dispatchToken]);

@@ -102,7 +107,2 @@ * FlightPriceStore.price =

* break;
*
* case 'city-update':
* FlightPriceStore.price =
* FlightPriceStore(CountryStore.country, CityStore.city);
* break;
* }

@@ -116,8 +116,11 @@ * });

var Dispatcher = (function () {
function Dispatcher() {
this.$Dispatcher_callbacks = {};
this.$Dispatcher_isPending = {};
this.$Dispatcher_isHandled = {};
this.$Dispatcher_isDispatching = false;
this.$Dispatcher_pendingPayload = null;
_classCallCheck(this, Dispatcher);
this._callbacks = {};
this._isDispatching = false;
this._isHandled = {};
this._isPending = {};
this._lastID = 1;
}

@@ -128,9 +131,7 @@

* a token that can be used with `waitFor()`.
*
* @param {function} callback
* @return {string}
*/
Dispatcher.prototype.register=function(callback) {
var id = _prefix + _lastID++;
this.$Dispatcher_callbacks[id] = callback;
Dispatcher.prototype.register = function register(callback) {
var id = _prefix + this._lastID++;
this._callbacks[id] = callback;
return id;

@@ -141,12 +142,7 @@ };

* Removes a callback based on its token.
*
* @param {string} id
*/
Dispatcher.prototype.unregister=function(id) {
invariant(
this.$Dispatcher_callbacks[id],
'Dispatcher.unregister(...): `%s` does not map to a registered callback.',
id
);
delete this.$Dispatcher_callbacks[id];
Dispatcher.prototype.unregister = function unregister(id) {
!this._callbacks[id] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.unregister(...): `%s` does not map to a registered callback.', id) : invariant(false) : undefined;
delete this._callbacks[id];
};

@@ -158,27 +154,14 @@

* response to a dispatched payload.
*
* @param {array<string>} ids
*/
Dispatcher.prototype.waitFor=function(ids) {
invariant(
this.$Dispatcher_isDispatching,
'Dispatcher.waitFor(...): Must be invoked while dispatching.'
);
Dispatcher.prototype.waitFor = function waitFor(ids) {
!this._isDispatching ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.waitFor(...): Must be invoked while dispatching.') : invariant(false) : undefined;
for (var ii = 0; ii < ids.length; ii++) {
var id = ids[ii];
if (this.$Dispatcher_isPending[id]) {
invariant(
this.$Dispatcher_isHandled[id],
'Dispatcher.waitFor(...): Circular dependency detected while ' +
'waiting for `%s`.',
id
);
if (this._isPending[id]) {
!this._isHandled[id] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.waitFor(...): Circular dependency detected while ' + 'waiting for `%s`.', id) : invariant(false) : undefined;
continue;
}
invariant(
this.$Dispatcher_callbacks[id],
'Dispatcher.waitFor(...): `%s` does not map to a registered callback.',
id
);
this.$Dispatcher_invokeCallback(id);
!this._callbacks[id] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.waitFor(...): `%s` does not map to a registered callback.', id) : invariant(false) : undefined;
this._invokeCallback(id);
}

@@ -189,20 +172,16 @@ };

* Dispatches a payload to all registered callbacks.
*
* @param {object} payload
*/
Dispatcher.prototype.dispatch=function(payload) {
invariant(
!this.$Dispatcher_isDispatching,
'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.'
);
this.$Dispatcher_startDispatching(payload);
Dispatcher.prototype.dispatch = function dispatch(payload) {
!!this._isDispatching ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.') : invariant(false) : undefined;
this._startDispatching(payload);
try {
for (var id in this.$Dispatcher_callbacks) {
if (this.$Dispatcher_isPending[id]) {
for (var id in this._callbacks) {
if (this._isPending[id]) {
continue;
}
this.$Dispatcher_invokeCallback(id);
this._invokeCallback(id);
}
} finally {
this.$Dispatcher_stopDispatching();
this._stopDispatching();
}

@@ -213,7 +192,6 @@ };

* Is this Dispatcher currently dispatching.
*
* @return {boolean}
*/
Dispatcher.prototype.isDispatching=function() {
return this.$Dispatcher_isDispatching;
Dispatcher.prototype.isDispatching = function isDispatching() {
return this._isDispatching;
};

@@ -225,9 +203,9 @@

*
* @param {string} id
* @internal
*/
Dispatcher.prototype.$Dispatcher_invokeCallback=function(id) {
this.$Dispatcher_isPending[id] = true;
this.$Dispatcher_callbacks[id](this.$Dispatcher_pendingPayload);
this.$Dispatcher_isHandled[id] = true;
Dispatcher.prototype._invokeCallback = function _invokeCallback(id) {
this._isPending[id] = true;
this._callbacks[id](this._pendingPayload);
this._isHandled[id] = true;
};

@@ -238,12 +216,12 @@

*
* @param {object} payload
* @internal
*/
Dispatcher.prototype.$Dispatcher_startDispatching=function(payload) {
for (var id in this.$Dispatcher_callbacks) {
this.$Dispatcher_isPending[id] = false;
this.$Dispatcher_isHandled[id] = false;
Dispatcher.prototype._startDispatching = function _startDispatching(payload) {
for (var id in this._callbacks) {
this._isPending[id] = false;
this._isHandled[id] = false;
}
this.$Dispatcher_pendingPayload = payload;
this.$Dispatcher_isDispatching = true;
this._pendingPayload = payload;
this._isDispatching = true;
};

@@ -256,8 +234,11 @@

*/
Dispatcher.prototype.$Dispatcher_stopDispatching=function() {
this.$Dispatcher_pendingPayload = null;
this.$Dispatcher_isDispatching = false;
Dispatcher.prototype._stopDispatching = function _stopDispatching() {
delete this._pendingPayload;
this._isDispatching = false;
};
return Dispatcher;
})();
module.exports = Dispatcher;
module.exports = Dispatcher;
{
"name": "flux",
"version": "2.0.3",
"version": "2.1.0",
"description": "An application architecture based on a unidirectional data flow",

@@ -14,16 +14,16 @@ "keywords": [

"files": [
"LICENSE",
"PATENTS",
"README.md",
"flow",
"index.js",
"lib/",
"LICENSE",
"PATENTS"
"lib",
"utils.js"
],
"main": "index.js",
"scripts": {
"build": "gulp build",
"prepublish": "gulp publish",
"test": "jest"
"test": "NODE_ENV=test jest"
},
"jest": {
"rootDir": "src",
"scriptPreprocessor": "../jest-preprocessor.js"
},
"repository": {

@@ -37,17 +37,46 @@ "type": "git",

"Bill Fisher <fisherwebdev@gmail.com>",
"Paul O'Shannessy <paul@oshanessy.com>"
"Paul O'Shannessy <paul@oshanessy.com>",
"Kyle Davis <kyldvs@gmail.com>"
],
"license": "BSD",
"license": "BSD-3-Clause",
"devDependencies": {
"browserify": "^9.0.3",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-clean": "^0.3.1",
"gulp-react": "^2.0.0",
"gulp-replace": "^0.5.3",
"jest-cli": "^0.4.0",
"react-tools": "^0.12.0",
"run-sequence": "^1.0.2",
"vinyl-source-stream": "^1.0.0"
"babel": "^5.4.7",
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"del": "^1.2.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-flatten": "^0.1.1",
"gulp-util": "^3.0.6",
"jest-cli": "^0.4.18",
"object-assign": "^3.0.0",
"run-sequence": "^1.1.0",
"vinyl-source-stream": "^1.0.0",
"webpack": "^1.11.0",
"webpack-stream": "^2.1.0"
},
"dependencies": {
"fbemitter": "^2.0.0",
"fbjs": "0.1.0-alpha.7",
"immutable": "^3.7.4"
},
"jest": {
"modulePathIgnorePatterns": [
"/lib/",
"/node_modules/"
],
"persistModuleRegistryBetweenSpecs": true,
"preprocessorIgnorePatterns": [
"/node_modules/"
],
"rootDir": "",
"scriptPreprocessor": "scripts/jest/preprocessor.js",
"setupEnvScriptFile": "scripts/jest/environment.js",
"testPathDirs": [
"<rootDir>/src"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/(?!fbemitter)"
]
}
}

@@ -20,5 +20,7 @@ # Flux

Flux Utils example : [TodoMVC](https://github.com/facebook/flux/tree/master/examples/flux-utils-todomvc)
## Requirements
Flux is more of a pattern than a framework, and does not have any hard dependencies. However, we often use [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) as a basis for `Stores` and [React](https://github.com/facebook/react) for our `Views`. The one piece of Flux not readily available elsewhere is the `Dispatcher`. This module is available here to complete your Flux toolbox. The Dispatcher's one dependency is the `invariant` module, also included here.
Flux is more of a pattern than a framework, and does not have any hard dependencies. However, we often use [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) as a basis for `Stores` and [React](https://github.com/facebook/react) for our `Views`. The one piece of Flux not readily available elsewhere is the `Dispatcher`. This module, along with some other utilities, is available here to complete your Flux toolbox.

@@ -35,6 +37,35 @@

## Flux Utils
We have also provided some basic utility classes to help get you started with Flux. These base classes are a solid foundation for a simple Flux application, but they are **not** a feature-complete framework that will handle all use cases. There are many other great Flux frameworks out there if these utilities do not fulfill your needs.
```js
import {ReduceStore} from 'flux/utils';
class CounterStore extends ReduceStore<number> {
getInitialState(): number {
return 0;
}
reduce(state: number, action: Object): number {
switch (action.type) {
case 'increment':
return state + 1;
case 'square':
return state * state;
default:
return state;
}
}
}
```
Check out the [example](https://github.com/facebook/flux/tree/master/examples/flux-utils-todomvc) and [documentation](https://facebook.github.io/flux/docs/flux-utils.html) for more information.
## Building Flux from a Cloned Repo
Clone the repo and navigate into the resulting `flux` directory. Then run `npm install`.
This will run [Gulp](http://gulpjs.com/)-based build tasks automatically and produce the file Flux.js, which you can then require as a module.
This will run [Gulp](http://gulpjs.com/)-based build tasks automatically and produce the file Flux.js, which you can then require as a module.

@@ -71,3 +102,3 @@ You could then require the Dispatcher like so:

## Join the Flux community
See the CONTRIBUTING file for how to help out.
See the [CONTRIBUTING](/CONTRIBUTING.md) file for how to help out.

@@ -74,0 +105,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc