Yomguithereal / baobab

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

nested monkey errors when listening to undefined path #422

Closed tnrich closed 8 years ago

tnrich commented 8 years ago

Hey @Yomguithereal , this one is a little bit tricky and might be hard to debug. I haven't yet been able to produce a simplified test-case for it, but at least it is reproducible within the repo I'm in.

Here's the code that produces the bug:

import Model from 'cerebral-model-baobab';
const state = Model({
    // completed: monkey([
    //             ['cerebralForm','SelectProductPage','completed'],
    //             function(completed) {
    //                 return completed ? true : false
    //             }
    //         ]),
    pages: {
        // completed: monkey([
        //         ['cerebralForm','SelectProductPage','completed'],
        //         function(completed) {
        //             return completed ? true : false
        //         }
        //     ]),
    },
}, {
    lazyMonkeys: false
})

When the first comment block is commented in, no error occurs, everything just runs as it should. However, if the second comment block is commented in, I'm getting this error:

image

As you can see, the error is getting triggered by the cerebral devtools.

image

Let me know what other info/setup I can provide you with to help you out.

Thanks!

abalmos commented 8 years ago

@Yomguithereal I have the same issue as @tnrich. Any Monkey that is not at the root the of the state tree results in the above error.

Yomguithereal commented 8 years ago

Hello @tnrich and @abalmos. Can you tell me if you are able to reproduce the bug with raw Baobab outside of the cerebral Model please?

Zache commented 8 years ago

I get the bug and we are only using React and Baobab, so it's not a Cerebral issue.

Yomguithereal commented 8 years ago

Ok. Can you show me the use case @Zache? Or does the one shown at the beginning at this issue, without cerebral decorum work?

Zache commented 8 years ago

@Yomguithereal I'm working on making an isolated repro, but it's not cooperating with me right now :cry:

Zache commented 8 years ago
var Baobab = require('baobab');
var Monkey = Baobab.monkey;

var baobab = new Baobab({
    blubb: {
        data: {
            name: 'zacharias',
            primes: [2, 3, 5, 7, 11],
            doubler: Monkey(['.', 'primes'], primes => primes.map(n => n * 2))
        },
        other: {
            trippler: Monkey(['..', 'data', 'primes'], n => n * 3)
        }
    }
});

baobab.merge(['blubb'], { data: { stuff: 13, primes: [2, 3, 5, 7] } });
Yomguithereal commented 8 years ago

Thanks @Zache. I will look into it.

Yomguithereal commented 8 years ago

Version 2.3.2 is now released.

abalmos commented 8 years ago

@Yomguithereal Thanks for quick response! However, it seems that with 2.3.2 the trippler monkey function is called twice. Once with the new array of primes and once with undefined (which of course breaks the monkey).

Here is the updated example case:

var Baobab = require('baobab');
var Monkey = Baobab.monkey;

var baobab = new Baobab({
    blubb: {
        data: {
            name: 'zacharias',
            primes: [2, 3, 5, 7, 11],
            doubler: Monkey(['.', 'primes'], primes => primes.map(n => n * 2))
        },
        other: {
            trippler: Monkey(['..', 'data', 'primes'], n => n.map(n * 3))
        }
    }
});

baobab.merge(['blubb'], { data: { stuff: 13, primes: [2, 3, 5, 7] } });
baobab.get(['blubb', 'other', 'trippler']);