Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Add documentation about differences between our implementation and Fa…
Browse files Browse the repository at this point in the history
…cebook dispatcher
  • Loading branch information
mridgway committed Aug 15, 2014
1 parent f3f2448 commit 5a5e839
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ dispatcher.dispatch('NAVIGATE', {});
// Action has been handled fully
```

## 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 isolates stores between requests on the server-side, we have opted to make the dispatcher and stores classes that are instantiated per request. They stores are still singletons within the scope of a request though.

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

### registerStore(store)

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:

* `context`: A context object that will be made available to all stores. Useful for request or session level settings.

Expand Down Expand Up @@ -102,7 +110,7 @@ ExampleStore.handlers = {
};
```

The handler function will be passed two parameters:
The handler function will be passed one parameter:

* `payload`: An object containing action information.

Expand Down

0 comments on commit 5a5e839

Please sign in to comment.