diff --git a/packages/frptools/README.md b/packages/frptools/README.md index 98b11c2..c1caeee 100644 --- a/packages/frptools/README.md +++ b/packages/frptools/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)); 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. diff --git a/packages/frptools/package.json b/packages/frptools/package.json index b438747..69a938d 100644 --- a/packages/frptools/package.json +++ b/packages/frptools/package.json @@ -1,6 +1,6 @@ { "name": "frptools", - "version": "3.0.0", + "version": "3.0.1", "description": "Observable Property and Computed data streams", "main": "lib/index.js", "jsnext:main": "src/index.js", diff --git a/packages/frptools/src/index.js b/packages/frptools/src/index.js index f2b5de3..c7d8ddc 100644 --- a/packages/frptools/src/index.js +++ b/packages/frptools/src/index.js @@ -1,4 +1,4 @@ export { prop } from './property'; export { computed } from './computed'; export { container } from './container'; -export { call, id } from './util.js'; +export { call, id, pick } from './util.js'; diff --git a/packages/frptools/src/util.js b/packages/frptools/src/util.js index 6222d3a..4225947 100644 --- a/packages/frptools/src/util.js +++ b/packages/frptools/src/util.js @@ -1,5 +1,11 @@ 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 => { subscriptionsArray.push(fn); return () => { @@ -11,8 +17,6 @@ export const registerSubscriptions = subscriptionsArray => fn => { }; }; -export const call = a => (typeof a === 'function' ? a() : a); - export const registerFire = subscriptionsArray => val => { subscriptionsArray.map(s => s(val)).forEach(call); }; diff --git a/packages/gallery/src/interface/components/appbar.js b/packages/gallery/src/interface/components/appbar.js index f2229b8..664aa2f 100644 --- a/packages/gallery/src/interface/components/appbar.js +++ b/packages/gallery/src/interface/components/appbar.js @@ -1,8 +1,7 @@ -import { prop, computed, container } from 'frptools'; +import { prop, computed, container, pick } from 'frptools'; import { Icon } from './icon.js'; import { defineElement as el, subscribeToRender } from '../../utils/domvm.js'; -import { pick } from '../../utils/conversion.js'; import { injectStyle, styled } from '../../services/style.js'; import { CLICKABLE } from '../styles.js'; diff --git a/packages/gallery/src/utils/conversion.js b/packages/gallery/src/utils/conversion.js index 10a34e1..e5144f1 100644 --- a/packages/gallery/src/utils/conversion.js +++ b/packages/gallery/src/utils/conversion.js @@ -1,4 +1,6 @@ import { readAsArrayBuffer } from 'pouchdb-binary-utils'; +import { pick } from 'frptools'; + import { isObject } from './comparators'; export function bufferToHexString(buffer) { @@ -45,8 +47,6 @@ export function deepAssign(to, ...rest) { return to; } -export const pick = (id, def) => doc => (doc && doc.hasOwnProperty(id) ? doc[id] : def); - export const extractID = pick('_id'); export const extractREV = pick('_rev');