Skip to content

Commit

Permalink
Merge pull request #31 from swipely/fix-stakeout-path
Browse files Browse the repository at this point in the history
Stakeout update path was sometimes a string
  • Loading branch information
Andrew Goodale authored Aug 29, 2017
2 parents dab29a4 + cb43ec4 commit 258438e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/find_closest_transmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const findClosestTransmitter = function (type, dataStore, path) {
pathStr = parts.join('.');

if (pathStr.length === 0) {
throw new Error("Couldn't find " + type + " for " + pathStr);
throw new Error("Couldn't find " + type + " for " + path.join('.'));
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/stakeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function notifyStakeouts(update, rootCursor) {

if (path === '') {
// This is a "set" call on the root cursor, so notify based on the properties of the new value
each(update.value, (v, key) => notifyStakeouts({ path: key, value: v }, rootCursor));
each(update.value, (v, key) => {
notifyStakeouts({ path: [key], value: v, action: update.action }, rootCursor);
});
return;
}

Expand Down
19 changes: 19 additions & 0 deletions test/state_trooper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('StateTrooper', function () {

StateTrooper.stakeout('something.a', (cursor, update) => {
result.push(update.value);
expect(update.path).to.be.an(Array);

if (result.length === 3) {
expect( result ).to.eql([4, 5, 6])
Expand All @@ -122,5 +123,23 @@ describe('StateTrooper', function () {
cursor.refine('something.a').add(6);
});
});

it('handles top-level set()', function (done) {

StateTrooper.stakeout('something', (cursor, update) => {
expect(update.path).to.eql(['something']);
expect(update.value).to.have.key('b');
expect(update.action).to.eql('set');
done();
});

go(function* () {
let cursor = yield take(cursorChan);

cursor.set({
something: { b: [1, 2, 3, 4] }
});
});
});
});
});

0 comments on commit 258438e

Please sign in to comment.