Skip to content

Commit

Permalink
Merge pull request #18 from datavis-tech/set-only-changed
Browse files Browse the repository at this point in the history
Only Propagate Changed Properties
  • Loading branch information
curran authored Aug 28, 2018
2 parents 1f6a264 + 4103323 commit eb56e77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ const Topologica = options => {
};

const setProperty = ([property, value]) => {
values.set(property, value);
changed.add(property);
if (values.get(property) !== value) {
values.set(property, value);
changed.add(property);
}
};

const set = options => {
Expand Down
19 changes: 19 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,23 @@ describe('Topologica.js', () => {
a: 5
});
});

it('Should only propagate changes when values change.', () => {
let invocations = 0;

const state = Topologica({
b: λ(({a}) => invocations++, 'a')
});

assert.equal(invocations, 0);

state.set({ a: 2 });
assert.equal(invocations, 1);

state.set({ a: 2 });
assert.equal(invocations, 1);

state.set({ a: 99 });
assert.equal(invocations, 2);
});
});

0 comments on commit eb56e77

Please sign in to comment.