Skip to content

Creating a state tree

Christian Alfoni edited this page Mar 5, 2015 · 2 revisions
var Baobab = require('baobab');

// You can use any data structure that reflects the
// UI of your application
var tree = new Baobab({
  home: {
    feed: {
      isLoading: false,
      items: []
    }
  }
});

module.exports = tree;

Big trees

You can split domains of your tree into different modules.

var Baobab = require('baobab');
var homeState = require('./states/home.js');
var adminState = require('./states/admin.js');
var profileState = require('./states/profile.js');

var tree = new Baobab({
  home: homeState,
  admin: adminState,
  profile: profileState
});

module.exports = tree;

states/home.js

module.exports = {
  feed: {
    isLoading: false,
    items: []
  }
};