Fix a bug with FRPtools when a container property is set to a falsey value

This commit is contained in:
Timothy Farrell 2018-09-11 12:57:14 -05:00
parent ee4edf7e55
commit ccd6410c28
3 changed files with 15 additions and 2 deletions

View File

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

View File

@ -2,6 +2,17 @@ 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

@ -48,7 +48,9 @@ export function container(store, hash) {
target[name] = newVal;
checkUpdate(target);
return newVal;
// 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;
}
});