Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facet error when using a cursor to change rendered component #211

Closed
cassiozen opened this issue May 4, 2015 · 6 comments
Closed

Facet error when using a cursor to change rendered component #211

cassiozen opened this issue May 4, 2015 · 6 comments
Labels

Comments

@cassiozen
Copy link

I Have a component that conditionally renders <Login /> or <Ok /> depending on a value on a Baobab tree:

var Main = React.createClass({
  mixins: [branch],
  cursors: {
    userCursor: ['user']
  },

  render() {
    if(this.state.userCursor.id === ''){
      return <Login />;
    } else {
      return <Ok />;
    }
  }
})

But as soon as the tree is updated and an user object is set, I get an "Cannot convert undefinded or null to object", on facet.js.

On facet.js, if I add a check before self.cursors everything works, but this is obviously not a permanent solution:

 this.updateHandler = function(e) {
    if(!self.cursors) return;
    var paths = Object.keys(self.cursors).map(function(k) {
      return self.cursors[k].solvedPath;
    })
@Yomguithereal
Copy link
Owner

Hello @cassiozen, I'll investigate this issue asap. In the meantime, could you show me what your app's state looks like, please?

@cassiozen
Copy link
Author

Sure:

var Baobab = require('baobab');

var tree = new Baobab({
  user: {
    id: '',
    username: '',
    firstname: '',
    lastname: '',
    email: '',
    avatar: ''
  },
  viewStates: {
    login: {
      invalidLogin: false,
      loading: false
    }
  }
});

module.exports = tree;

@Yomguithereal
Copy link
Owner

Ok @cassiozen, I traced the bug (a very nasty one I must say) and it seems the event emitter is the culprit here. I need to investigate some things and hopefully fix this.

@Yomguithereal
Copy link
Owner

Well it seems that emmett's behaviour is consistent with node's emitter (see this).

I therefore need to add a killed flag in the facet to avoid those kind of things.

@Yomguithereal
Copy link
Owner

Ok, tested this just now. This should be fixed as per last commit.

@jpablo
Copy link

jpablo commented May 6, 2015

Nice! this was affecting me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants