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
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
determine updated status. If the hash function is not supplied, every update will be propagated.
state and trigger subscribers if it is updated. An hash function must be applied to determine
updated status.
## Usage

View File

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

View File

@ -2,17 +2,6 @@ import { container, computed } from '../src/index.js';
import { dirtyMock, hashSet } from '../src/testUtil.js';
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', () => {
let runCount = 0;
let currentValue = new Set();

View File

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

View File

@ -15,7 +15,7 @@
"backgroundtask": "~1.0.0",
"body-parser": "~1.18.3",
"date-fns": "~1.29.0",
"domvm": "~3.4.5",
"domvm": "~3.2.1",
"exif-parser": "~0.1.9",
"express": "~4.16.3",
"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 = {
is: s => s && typeof s.subscribe === 'function',
val: s => s(),
sub: (s, fn) => s.subscribe(fn),
off: subList => subList.forEach(call),
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;
}
unsub: s => s()
};