Cerebral
A state controller with its own debugger
The Cerebral Webpage is now launched
You can access the webpage at http://christianalfoni.com/cerebral/. You will find all the information you need there.
How to create a custom Cerebral VIEW package
view packages in Cerebral just uses an instantiated Cerebral controller to get state, do state changes and listen to state changes. The package you create basically just needs an instance of a Cerebral controller and you will have access to the following information.
function myCustomViewPackage (controller) {
controller.get(path);
controller.on('change', function () {
});
controller.on('remember', function () {
});
};
That is basically all need to update the view layer.
How to create a custom Cerebral MODEL package
In this example we will use the immutable-store project as a model.
index.js
var Store = require('immutable-store');
var getValue = function (path, obj) {
path = path.slice();
while (path.length) {
obj = obj[path.shift()];
}
return obj;
};
module.exports = function (state) {
return function (controller) {
var initialState = Store(state);
state = initialState;
controller.on('reset', function () {
state = initialState;
});
controller.on('seek', function (seek, isPlaying, recording) {
state = state.import(recording.initialState);
});
return {
get: function (path) {
return pathToValue(path, state);
},
toJSON: function () {
return state.toJS();
},
getInitialRecordingState: function () {
return state.export();
},
mutators: {
set: function (path, value) {
var key = path.pop();
state = getValue(path, state).set(key, value);
}
}
};
};
};
Demos
TodoMVC: www.christianalfoni.com/todomvc
Cerebral - The beginning
Read this article introducing Cerebral: Cerebral developer preview
Contributors
- Marc Macleod: Discussions and code contributions
- Petter Stenberg Hansen: Logo and illustrations
- Jesse Wood: Article review
Thanks guys!