Compare commits

..

No commits in common. "c618de8e4c7c3b78ea7944d0c6791c96802f6abe" and "b6536700afd7076ff40a9f4bd9532b474098e82d" have entirely different histories.

6 changed files with 11 additions and 34 deletions

View File

@ -190,8 +190,8 @@ them.
## Behavior ## Behavior
Anytime a property is set or a method is gotten and called, the container will check for an updated Anytime a property is set or a method is gotten and called, the container will check for an updated
state and trigger subscribers if it is updated. An optional hash function may be applied to state and trigger subscribers if it is updated. An hash function must be applied to determine
determine updated status. If the hash function is not supplied, every update will be propagated. updated status.
## Usage ## Usage

View File

@ -1,6 +1,6 @@
{ {
"name": "frptools", "name": "frptools",
"version": "3.2.3", "version": "3.2.1",
"description": "Observable Property and Computed data streams", "description": "Observable Property and Computed data streams",
"main": "src/index.js", "main": "src/index.js",
"files": [ "files": [

View File

@ -2,17 +2,6 @@ import { container, computed } from '../src/index.js';
import { dirtyMock, hashSet } from '../src/testUtil.js'; import { dirtyMock, hashSet } from '../src/testUtil.js';
describe('A container', () => { describe('A container', () => {
it('tracks properties', () => {
let i = 0;
const a = container({}, () => i++);
a.a = 1;
expect(a.a).toBe(a._.a);
a.b = false;
expect(a.b).toBe(a._.b);
});
it('notifies dependents of updates', () => { it('notifies dependents of updates', () => {
let runCount = 0; let runCount = 0;
let currentValue = new Set(); let currentValue = new Set();

View File

@ -2,7 +2,7 @@ import { registerSubscriptions, registerFire } from './util.js';
export function container(store, hash) { export function container(store, hash) {
let subscribers = []; let subscribers = [];
let id = hash && hash(store); let id = hash(store);
const containerMethods = { const containerMethods = {
subscribe: registerSubscriptions(subscribers), subscribe: registerSubscriptions(subscribers),
@ -13,8 +13,8 @@ export function container(store, hash) {
}; };
function checkUpdate(target) { function checkUpdate(target) {
let newId = hash && hash(target); const newId = hash(target);
if (!hash || id !== newId) { if (id !== newId) {
id = newId; id = newId;
containerMethods.fire(target); containerMethods.fire(target);
} }
@ -48,9 +48,7 @@ export function container(store, hash) {
target[name] = newVal; target[name] = newVal;
checkUpdate(target); checkUpdate(target);
// Returning a falsey value causes TypeError return newVal;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set#Invariants
return newVal || true;
} }
}); });

View File

@ -15,7 +15,7 @@
"backgroundtask": "~1.0.0", "backgroundtask": "~1.0.0",
"body-parser": "~1.18.3", "body-parser": "~1.18.3",
"date-fns": "~1.29.0", "date-fns": "~1.29.0",
"domvm": "~3.4.5", "domvm": "~3.2.1",
"exif-parser": "~0.1.9", "exif-parser": "~0.1.9",
"express": "~4.16.3", "express": "~4.16.3",
"frptools": "~3.2.0", "frptools": "~3.2.0",

View File

@ -1,18 +1,8 @@
import { call } from 'frptools'; import { log, group, groupEnd } from '../utils/console.js';
export const streamConfig = { export const streamConfig = {
is: s => s && typeof s.subscribe === 'function', is: s => s && typeof s.subscribe === 'function',
val: s => s(),
sub: (s, fn) => s.subscribe(fn), sub: (s, fn) => s.subscribe(fn),
off: subList => subList.forEach(call), unsub: s => s()
on: (accum, vm) => {
const redraw = () => vm.redraw();
return accum.map(s => (streamConfig.is(s) ? streamConfig.sub(s, redraw) : s()));
},
val: (s, accum) =>{
if (streamConfig.is(s)) {
accum.push(s);
return s();
}
return s;
}
}; };