Comparing version 0.3.3 to 1.0.0
@@ -6,3 +6,3 @@ Contributing Code to `dispatchr` | ||
[BSD license]: https://github.com/yahoo/dispatchr/blob/master/LICENSE.md | ||
[BSD license]: https://github.com/yahoo/fluxible/blob/master/LICENSE.md | ||
[CLA]: https://yahoocla.herokuapp.com/ |
@@ -7,3 +7,2 @@ /** | ||
var Action = require('./Action'); | ||
var DEFAULT = 'default'; | ||
@@ -10,0 +9,0 @@ var DispatcherContext = require('./DispatcherContext'); |
@@ -25,2 +25,3 @@ /** | ||
}; | ||
this.rehydratedStoreState = {}; | ||
} | ||
@@ -43,2 +44,9 @@ | ||
this.storeInstances[storeName] = new (this.dispatcher.stores[storeName])(this.dispatcherInterface); | ||
if (this.rehydratedStoreState && this.rehydratedStoreState[storeName]) { | ||
var state = this.rehydratedStoreState[storeName]; | ||
if (this.storeInstances[storeName].rehydrate) { | ||
this.storeInstances[storeName].rehydrate(state); | ||
} | ||
this.rehydratedStoreState[storeName] = null; | ||
} | ||
} | ||
@@ -49,3 +57,3 @@ return this.storeInstances[storeName]; | ||
/** | ||
* Dispatches a new action or queues it up if one is already in progress | ||
* Dispatches a new action or throws if one is already in progress | ||
* @method dispatch | ||
@@ -132,7 +140,3 @@ * @param {String} actionName Name of the action to be dispatched | ||
Object.keys(dispatcherState.stores).forEach(function storeStateEach(storeName) { | ||
var state = dispatcherState.stores[storeName], | ||
store = self.getStore(storeName); | ||
if (store.rehydrate) { | ||
store.rehydrate(state); | ||
} | ||
self.rehydratedStoreState[storeName] = dispatcherState.stores[storeName]; | ||
}); | ||
@@ -139,0 +143,0 @@ } |
{ | ||
"name": "dispatchr", | ||
"version": "0.3.3", | ||
"version": "1.0.0", | ||
"description": "A Flux dispatcher for applications that run on the server and the client.", | ||
@@ -8,14 +8,14 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/yahoo/dispatchr.git" | ||
"url": "git://github.com/yahoo/fluxible.git" | ||
}, | ||
"scripts": { | ||
"cover": "node node_modules/istanbul/lib/cli.js cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --reporter spec", | ||
"lint": "./node_modules/.bin/jshint lib tests", | ||
"test": "./node_modules/.bin/mocha tests/unit/ --recursive --reporter spec" | ||
"test": "../../node_modules/.bin/mocha tests/unit/ --recursive --compilers js:babel-register --reporter spec", | ||
"cover": "../../node_modules/.bin/istanbul cover --dir artifacts -- ../../node_modules/.bin/_mocha tests/unit/ --recursive --compilers js:babel-register --reporter spec", | ||
"lint": "../../node_modules/.bin/eslint lib/ addons/ utils/ index.js" | ||
}, | ||
"author": "Michael Ridgway <mridgway@yahoo-inc.com", | ||
"author": "Michael Ridgway <mridgway@yahoo-inc.com>", | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "https://github.com/yahoo/dispatchr/blob/master/LICENSE.md" | ||
"type": "BSD-3-Clause", | ||
"url": "https://github.com/yahoo/fluxible/blob/master/LICENSE.md" | ||
} | ||
@@ -28,12 +28,2 @@ ], | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"coveralls": "^2.11.1", | ||
"istanbul": "^0.3.2", | ||
"jshint": "^2.5.1", | ||
"mocha": "^2.0.1" | ||
}, | ||
"jshintConfig": { | ||
"node": true | ||
}, | ||
"keywords": [ | ||
@@ -40,0 +30,0 @@ "yahoo", |
# Dispatchr | ||
[![npm version](https://badge.fury.io/js/dispatchr.svg)](http://badge.fury.io/js/dispatchr) | ||
[![Build Status](https://travis-ci.org/yahoo/dispatchr.svg?branch=master)](https://travis-ci.org/yahoo/dispatchr) | ||
[![Dependency Status](https://david-dm.org/yahoo/dispatchr.svg)](https://david-dm.org/yahoo/dispatchr) | ||
[![devDependency Status](https://david-dm.org/yahoo/dispatchr/dev-status.svg)](https://david-dm.org/yahoo/dispatchr#info=devDependencies) | ||
[![Coverage Status](https://coveralls.io/repos/yahoo/dispatchr/badge.png?branch=master)](https://coveralls.io/r/yahoo/dispatchr?branch=master) | ||
A [Flux](http://facebook.github.io/flux/docs/overview.html) dispatcher for applications that run on the server and the client. | ||
A [Flux][] dispatcher for applications that run on the server and the client. | ||
## Usage | ||
For a more detailed example, see our [example application](https://github.com/yahoo/flux-example). | ||
For a more detailed example, see our [example applications](../../examples). | ||
@@ -24,3 +20,3 @@ ```js | ||
dispatcher.dispatch('NAVIGATE', {}); | ||
dispatcherContext.dispatch('NAVIGATE', {}); | ||
// Action has been handled fully | ||
@@ -31,17 +27,33 @@ ``` | ||
Dispatchr's main goal is to facilitate server-side rendering of Flux applications while also working on the client-side to encourage code reuse. In order to isolate stores between requests on the server-side, we have opted to instantiate the dispatcher and stores classes per request. | ||
Dispatchr's main goal is to facilitate server-side rendering of Flux | ||
applications while also working on the client-side to encourage code reuse. In | ||
order to isolate stores between requests on the server-side, we have opted to | ||
instantiate the dispatcher and stores classes per request. | ||
In addition, action registration is done by stores as a unit rather than individual callbacks. This allows us to lazily instantiate stores as the events that they handle are dispatched. Since instantiation of stores is handled by the dispatcher, we can keep track of the stores that were used during a request and dehydrate their state to the client when the server has completed its execution. | ||
In addition, action registration is done by stores as a unit rather than | ||
individual callbacks. This allows us to lazily instantiate stores as the events | ||
that they handle are dispatched. Since instantiation of stores is handled by the | ||
dispatcher, we can keep track of the stores that were used during a request and | ||
dehydrate their state to the client when the server has completed its execution. | ||
Lastly, we are able to enforce the Flux flow by restricting access to the dispatcher from stores. Instead of stores directly requiring a singleton dispatcher, we pass a dispatcher interface to the constructor of the stores to provide access to only the functions that should be available to it: `waitFor` and `getStore`. This prevents the stores from dispatching an entirely new action, which should only be done by action creators to enforce the unidirectional flow that is Flux. | ||
Lastly, we are able to enforce the Flux flow by restricting access to the | ||
dispatcher from stores. Instead of stores directly requiring a singleton | ||
dispatcher, we pass a dispatcher interface to the constructor of the stores to | ||
provide access to only the functions that should be available to it: `waitFor` | ||
and `getStore`. This prevents the stores from dispatching an entirely new | ||
action, which should only be done by action creators to enforce the | ||
unidirectional flow that is Flux. | ||
## Helper Utilities | ||
These utilities make creating stores less verbose and provide some `change` related functions that are common amongst all store implementations. These store helpers also implement a basic `shouldDehydrate` function that returns true if `emitChange` has been called by the store and false otherwise. | ||
These utilities make creating stores less verbose and provide some `change` | ||
related functions that are common amongst all store implementations. These | ||
store helpers also implement a basic `shouldDehydrate` function that returns | ||
true if `emitChange` has been called by the store and false otherwise. | ||
### BaseStore | ||
`require('dispatchr/addons/BaseStore')` provides a base store class for extending. Provides `getContext`, `emitChange`, `addChangeListener`, and `removeChangeListener` functions. Example: | ||
`require('dispatchr/addons/BaseStore')` provides a base store class for | ||
extending. Provides `getContext`, `emitChange`, `addChangeListener`, and | ||
`removeChangeListener` functions. Example: | ||
@@ -66,3 +78,5 @@ ```js | ||
`require('dispatchr/addons/createStore')` provides a helper function for creating stores similar to React's `createClass` function. The created store class will extend BaseStore and have the same built-in functions. Example: | ||
`require('dispatchr/addons/createStore')` provides a helper function for | ||
creating stores similar to React's `createClass` function. The created store | ||
class will extend BaseStore and have the same built-in functions. Example: | ||
@@ -85,4 +99,4 @@ ```js | ||
- [Dispatchr](https://github.com/yahoo/dispatchr/blob/master/docs/dispatchr.md) | ||
- [Store](https://github.com/yahoo/dispatchr/blob/master/docs/store.md) | ||
- [Dispatchr](https://github.com/yahoo/fluxible/blob/master/packages/dispatchr/docs/dispatchr.md) | ||
- [Store](https://github.com/yahoo/fluxible/blob/master/packages/dispatchr/docs/store.md) | ||
@@ -96,2 +110,3 @@ | ||
[LICENSE file]: https://github.com/yahoo/dispatchr/blob/master/LICENSE.md | ||
[LICENSE file]: https://github.com/yahoo/fluxible/blob/master/LICENSE.md | ||
[Flux]: http://facebook.github.io/flux/docs/overview.html |
@@ -1,1 +0,1 @@ | ||
throw new Error("require('dispatchr/utils/BaseStore') has moved to require('dispatchr/addons/BaseStore')"); | ||
throw new Error('require(\'dispatchr/utils/BaseStore\') has moved to require(\'dispatchr/addons/BaseStore\')'); |
@@ -1,1 +0,1 @@ | ||
throw new Error("require('dispatchr/utils/createStore') has moved to require('dispatchr/addons/createStore')"); | ||
throw new Error('require(\'dispatchr/utils/createStore\') has moved to require(\'dispatchr/addons/createStore\')'); |
@@ -1,1 +0,1 @@ | ||
throw new Error("require('dispatchr/utils') has moved to require('dispatchr/addons')"); | ||
throw new Error('require(\'dispatchr/utils\') has moved to require(\'dispatchr/addons\')'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
513
1
108
25155
15