async-selector
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "async-selector", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Select values from databases using asynchronous selectors.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -123,4 +123,18 @@ A simple, lightweight library inspired by [reselect](https://github.com/reduxjs/reselect) which allows you select data out of a remote database almost as easily as you would from local state. This library will normally be used in conjunction with redux and reselect but it has no dependencies. | ||
``` | ||
### Handling stateful APIs | ||
Generally, a basic assumption of a selector is the function is pure - the inputs fully determine the output. Unfortunately, that is an assumption can't always be made when querying a database. For example, you might have a button that allows the user to refresh the data if the user is worried the data was changed. Fortunately, this isn't actually a big issue thanks to the "forceUpdate" parameter! | ||
``` | ||
function buttonClicked() { | ||
employeeAges(store.getState(), true) // "true" indicates that the selector should create a new promise regardless of whether the inputs changed | ||
} | ||
``` | ||
By passing true as the second parameter of the selector, the selector will be called as if the inputs changed thus automatically creating a new promise. | ||
# Documentation | ||
createAsyncSelector takes in two arguments: | ||
``` | ||
@@ -140,3 +154,6 @@ function createAsyncSelector(params, ...selectors) -> obj | ||
## selectors | ||
Each selector is a function that takes in state as its argument just like in reselect. It memoizes its results so the only way for it to return a different value for the same inputs is if it contained a promise that was resolved. | ||
Each selector is a function that takes in state as its argument just like in reselect. It memoizes its results so the only way for it to return a different value for the same inputs is if it contained a promise that was resolved. An async selector is only different from a normal selector in that you can pass in "forceUpdate" bool as the second parameter to force a promise to be made. | ||
``` | ||
function selector(state, forceUpdate=false) -> any | ||
``` | ||
## params | ||
@@ -143,0 +160,0 @@ params is an object |
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
125366
194