Comparing version 0.2.0 to 0.2.1
@@ -144,2 +144,3 @@ /** | ||
} | ||
debug('dispatching ' + actionName, payload); | ||
this.currentAction = new Action(actionName, payload); | ||
@@ -173,4 +174,2 @@ var self = this, | ||
stores[storeName] = store.dehydrate(); | ||
} else { | ||
stores[storeName] = store.getState(); | ||
} | ||
@@ -177,0 +176,0 @@ }); |
{ | ||
"name": "dispatchr", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A Flux dispatcher for applications that run on the server and the client.", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"chai": "^1.9.1", | ||
"coveralls": "^2.11.1", | ||
"istanbul": "^0.2.10", | ||
@@ -29,0 +30,0 @@ "jshint": "^2.5.1", |
@@ -1,2 +0,2 @@ | ||
# 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) | ||
# 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) [![Coverage Status](https://coveralls.io/repos/yahoo/dispatchr/badge.png?branch=master)](https://coveralls.io/r/yahoo/dispatchr?branch=master) | ||
@@ -22,2 +22,10 @@ A [Flux](http://facebook.github.io/react/docs/flux-overview.html) dispatcher for applications that run on the server and the client. | ||
## Differences from [Facebook's Flux Dispatcher](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/dispatcher/Dispatcher.js) | ||
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. | ||
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. | ||
## Dispatcher Interface | ||
@@ -27,7 +35,7 @@ | ||
A static method to register stores to Dispatchr making them available to handle actions and be accessible through `getStore` on Dispatchr instances. | ||
A static method to register stores to the Dispatcher class making them available to handle actions and be accessible through `getStore` on Dispatchr instances. | ||
### Constructor | ||
Creates a new instance of Dispatchr with the following parameters: | ||
Creates a new Dispatcher instance with the following parameters: | ||
@@ -64,4 +72,9 @@ * `context`: A context object that will be made available to all stores. Useful for request or session level settings. | ||
Dispatchr expects that your stores use the following interface: | ||
We have provided utilities for creating stores in a couple of forms: | ||
* `require('dispatchr/utils/createStore')` returns a `React.createClass`-like function for creating stores. | ||
* `require('dispatchr/utils/BaseStore')` returns an extendable class. | ||
You are not required to use these if you want to keep your stores completely decoupled from the dispatcher. Dispatchr expects that your stores use the following interface: | ||
### Constructor | ||
@@ -76,6 +89,10 @@ | ||
The constructor is also where the initial state of the store should be initialized. | ||
```js | ||
function ExampleStore(dispatcher) { | ||
this.dispatcher = dispatcher; | ||
this.getInitialState(); | ||
if (this.initialize) { | ||
this.initialize(); | ||
} | ||
} | ||
@@ -109,3 +126,3 @@ ``` | ||
The handler function will be passed two parameters: | ||
The handler function will be passed one parameter: | ||
@@ -121,8 +138,8 @@ * `payload`: An object containing action information. | ||
### getState() | ||
### dehydrate() | ||
The store should implement this function that will return a serializable data object that can be transferred from the server to the client and also be used by your components. | ||
The store should define this function to dehydrate the store if it will be shared between server and client. It should return a serializable data object that will be passed to the client. | ||
```js | ||
ExampleStore.prototype.getState = function () { | ||
ExampleStore.prototype.dehydrate = function () { | ||
return { | ||
@@ -134,10 +151,12 @@ navigating: this.navigating | ||
### dehydrate() | ||
### rehydrate(state) | ||
The store can optionally define this function to customize the dehydration of the store. It should return a serializable data object that will be passed to the client. | ||
The store should define this function to rehydrate the store if it will be shared between server and client. It should restore the store to the original state using the passed `state`. | ||
### rehydrate(state) | ||
```js | ||
ExampleStore.prototype.rehydrate = function (state) { | ||
this.navigating = state.navigating; | ||
}; | ||
``` | ||
The store can optionally define this function to customize the rehydration of the store. It should restore the store to the original state using the passed `state`. | ||
## License | ||
@@ -144,0 +163,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
58320
22
380
161
0
5