omniscientjs/immstruct — pull request #8 by Dashed (2014-12-14 10:07:08+00:00)
Title: Patch handlePersisting(), and set correct structure during add, change, delete events.

This PR corrects the following issues:
- Modifying structure during add, change, or delete events doesn't work. It just reverts to the structure that fired the add, change, or delete events. This is an issue when updating value at a key path to anything but string, numbers and `true`.

- Deleting by key path (e.g `Cursor.remove(key)`) doesn't actually delete the key path from the structure. Instead, value at key path is set to `undefined`.

- Properly emit correct event (add, change, delete) when updating value at key path to falsey value (e.g. `void 0`, `false`, etc).

- Better heuristic on detecting existence of key path within a cursor by using `notSetValue`.

----

The PR stems from my attempts to emulate `waitFor` in flux based on cursor key paths:
```js
var
immstruct = require('immstruct'),
Immutable = require('immutable');

var structure = immstruct({});

structure.on('swap', function(newStructure, oldStructure) {

console.log('old struct:', oldStructure.toJS());
console.log('new struct:', newStructure.toJS());
});

// This works
// structure.once('swap', function(newStructure, oldStructure) {
// structure.cursor('profile').update('email', function() {
// return 'bob@bob.com';
// });
// });

// This doesn't work...
structure.once('add', function(path, newValue) {

if(path.join('/') !== 'profile')
return;

structure.cursor(path).update('email', function() {
return 'bob@bob.com';
});

});

structure.cursor('profile').update(function() {
return Immutable.fromJS({
name: 'bob'
});
});

console.log('final structure:', structure.cursor().toJS());
// output:
// old struct: {}
// new struct: { profile: { email: 'bob@bob.com' } }
// old struct: {}
// new struct: { profile: { name: 'bob' } }
// final structure: { profile: { name: 'bob' } }
```