Add pick to frptools. Document all utility functions
This commit is contained in:
parent
b51a8bf6d3
commit
a564006110
25
README.md
25
README.md
@ -228,3 +228,28 @@ node to use to propagate updates but firing other values could have some uses.
|
|||||||
const unsubscribe = inViewport.subscribe(console.log.bind(console));
|
const unsubscribe = inViewport.subscribe(console.log.bind(console));
|
||||||
inViewport.fire(false); // "false" logged to console.
|
inViewport.fire(false); // "false" logged to console.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Utilities
|
||||||
|
|
||||||
|
## id
|
||||||
|
|
||||||
|
`id(anything) -> anything`
|
||||||
|
|
||||||
|
`id` is a function that returns its first parameter. It is used as the default hash function for
|
||||||
|
each subscribable.
|
||||||
|
|
||||||
|
## call
|
||||||
|
|
||||||
|
`call(anything) -> void`
|
||||||
|
|
||||||
|
`call` will call the first parameter if it is a function. It is used for iterating over
|
||||||
|
subscribables.
|
||||||
|
|
||||||
|
## pick
|
||||||
|
|
||||||
|
`pick(propName, default) -> (obj) -> any`
|
||||||
|
|
||||||
|
`pick` returns a function that accepts an object and will return the object's property for the
|
||||||
|
provided name or the default if one is supplied. `pick` is not directly used with any subscribable
|
||||||
|
but can be useful as the computed function when breaking down a `prop` that contains an object or a
|
||||||
|
container.
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "frptools",
|
"name": "frptools",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"description": "Observable Property and Computed data streams",
|
"description": "Observable Property and Computed data streams",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"jsnext:main": "src/index.js",
|
"jsnext:main": "src/index.js",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export { prop } from './property';
|
export { prop } from './property';
|
||||||
export { computed } from './computed';
|
export { computed } from './computed';
|
||||||
export { container } from './container';
|
export { container } from './container';
|
||||||
export { call, id } from './util.js';
|
export { call, id, pick } from './util.js';
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
export const id = a => a;
|
export const id = a => a;
|
||||||
|
|
||||||
|
export const pick = (id, def) => doc => (doc && doc.hasOwnProperty(id) ? doc[id] : def);
|
||||||
|
|
||||||
|
export const call = a => (typeof a === 'function' ? a() : a);
|
||||||
|
|
||||||
|
// internal utilities
|
||||||
|
|
||||||
export const registerSubscriptions = subscriptionsArray => fn => {
|
export const registerSubscriptions = subscriptionsArray => fn => {
|
||||||
subscriptionsArray.push(fn);
|
subscriptionsArray.push(fn);
|
||||||
return () => {
|
return () => {
|
||||||
@ -11,8 +17,6 @@ export const registerSubscriptions = subscriptionsArray => fn => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const call = a => (typeof a === 'function' ? a() : a);
|
|
||||||
|
|
||||||
export const registerFire = subscriptionsArray => val => {
|
export const registerFire = subscriptionsArray => val => {
|
||||||
subscriptionsArray.map(s => s(val)).forEach(call);
|
subscriptionsArray.map(s => s(val)).forEach(call);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user