flux-commons-store
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "flux-commons-store", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Base Store class to use with Flux/Dispatcher", | ||
@@ -5,0 +5,0 @@ "main": "dist/store.js", |
# Flux Commons Store | ||
Base Store class to use with Flux/Dispatcher from Facebook. The idea is to have a clean | ||
and simple API to interact with the Facebook Dispatcher and register handlers. | ||
The missing Store class to use with facebook/flux Dispatcher (https://github.com/facebook/flux). | ||
* NO string matching (no more switch/case with huge constants file full of strings) | ||
* Smart matching, define one handler and match in a generic fashion multiple actions. (i.e: If ANY 402 status code then do something) | ||
## Usage | ||
```js | ||
var Store = require('flux-commons').Store; | ||
var Store = require('flux-commons-store'); | ||
var appDispatcher = require('./app_dispatcher'); | ||
@@ -30,17 +32,14 @@ var Actions = require('./actions'); | ||
## Matchers | ||
### Custom matchers | ||
```js | ||
listenToActionWithTags (tags, handler, deferExecution) { | ||
if (! (tags instanceof Array)) { | ||
tags = [tags]; | ||
} | ||
var matcher = function(action, params) { | ||
var matchedTagsCount = _.intersection(action.tags, tags).length; | ||
return matchedTagsCount === tags.length; | ||
}; | ||
function matcher(action, params) { | ||
return params.response.status === 401; | ||
} | ||
this.listenToMatchingAction(matcher, handler, deferExecution); | ||
} | ||
myStore.listenToMatchingAction(matcher, handleUnauthorized); | ||
function handleUnauthorized() { ... } // Delete the token or any other aciton required by your App. | ||
``` |
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
11308
45