Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 117 forks source link

Way to check field for monkey stuff #420

Closed eugeny-dementev closed 8 years ago

eugeny-dementev commented 8 years ago
var Baobab = require('baobab');

var tree = new Baobab({
  obj: {
    one: 'data',
    two: 'data'
  },
  key: 'three',
  comp: Baobab.monkey(
    ['obj'], 
    ['key'], 
    (obj, key) => obj[key]
  )
});

tree.exists(['comp']); // false

Is there any way to check field for monkey type? Something like tree.isMonkey(['comp'])?

Yomguithereal commented 8 years ago

Hello @eugeny-dementev. Fist of all, the fact that exists return false seems to be a bug. Now concerning the monkey part, other people mention that this would be a good idea to create something of the kind, so I will probably do it.

For the time being, a dirty workaround is to poll tree._monkeys which is a nested object containing dynamic paths.

eugeny-dementev commented 8 years ago

Actually i just recheck .exists with mokey field and looks like it work fine in last verion. It false only in 2.0. But not found any fixes about this in release notes.

Yomguithereal commented 8 years ago

My bad. Must have forgotten it in the changelog.

Yomguithereal commented 8 years ago

I just added the internal getMonkey method to the tree. The methods return a Monkey instance if found or else null.