New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cerebral

Package Overview
Dependencies
Maintainers
1
Versions
638
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebral - npm Package Compare versions

Comparing version 0.28.2 to 0.29.0

demo/modules/App/components/App/index.js

59

demo/main.js

@@ -7,44 +7,27 @@ import './../node_modules/todomvc-common/base.css';

import ReactDOM from 'react-dom';
import App from './App.js';
import controller from './controller.js';
import Controller from './../src/index.js';
import Model from 'cerebral-baobab';
import {Container} from 'cerebral-react';
import CerebralRouter from 'cerebral-router';
import allTodosClicked from './signals/allTodosClicked.js';
import newTodoTitleChanged from './signals/newTodoTitleChanged.js';
import newTodoSubmitted from './signals/newTodoSubmitted.js';
import removeTodoClicked from './signals/removeTodoClicked.js';
import toggleCompletedChanged from './signals/toggleCompletedChanged.js';
import toggleAllChanged from './signals/toggleAllChanged.js';
import filterClicked from './signals/filterClicked.js';
import clearCompletedClicked from './signals/clearCompletedClicked.js';
import todoDoubleClicked from './signals/todoDoubleClicked.js';
import newTitleChanged from './signals/newTitleChanged.js';
import newTitleSubmitted from './signals/newTitleSubmitted.js';
import recordClicked from './signals/recordClicked.js';
import playClicked from './signals/playClicked.js';
import stopClicked from './signals/stopClicked.js';
import App from './modules/App/components/App';
import AppModule from './modules/App';
controller.signal('allTodosClicked', allTodosClicked);
controller.signal('newTodoTitleChanged', newTodoTitleChanged);
controller.signal('newTodoSubmitted', newTodoSubmitted);
controller.signal('removeTodoClicked', removeTodoClicked);
controller.signal('toggleCompletedChanged', toggleCompletedChanged);
controller.signal('toggleAllChanged', toggleAllChanged);
controller.signal('filterClicked', filterClicked);
controller.signal('clearCompletedClicked', clearCompletedClicked);
controller.signal('todoDoubleClicked', todoDoubleClicked);
controller.signal('newTitleChanged', newTitleChanged);
controller.signal('newTitleSubmitted', newTitleSubmitted);
controller.signal('recordClicked', recordClicked);
controller.signal('playClicked', playClicked);
controller.signal('stopClicked', stopClicked);
import Refs from './modules/Refs';
import Recorder from 'cerebral-module-recorder';
import Router from './modules/Router';
// ROUTER
CerebralRouter(controller, {
'/': 'allTodosClicked',
'/:filter': 'filterClicked'
}, {
onlyHash: true,
baseUrl: '/todomvc/'
const controller = Controller(Model({}));
controller.registerModules({
app: AppModule(),
refs: Refs(),
recorder: Recorder(),
router: Router({
'/': 'app.footer.allTodosClicked',
'/:filter': 'app.footer.filterClicked'
}, {
onlyHash: true,
baseUrl: '/todomvc/'
})
});

@@ -51,0 +34,0 @@

{
"name": "cerebral",
"version": "0.28.2",
"version": "0.29.0",
"description": "A state controller with its own debugger",
"main": "src/index.js",
"scripts": {
"demo": "webpack-dev-server --progress --colors --content-base demo --config demo.config.js",
"deploydemo": "webpack --config demo.production.config.js",
"deploy": "NODE_ENV=production webpack -p",
"start": "webpack-dev-server --devtool eval --progress --colors --content-base build",
"demo": "webpack-dev-server --progress --colors --content-base demo --config demo/webpack.config.js",
"deploydemo": "webpack --config demo/webpack.config.js",
"devtest": "nodeunit-watcher",

@@ -18,3 +16,3 @@ "test": "nodeunit tests"

"babel-loader": "^5.3.2",
"cerebral-baobab": "^0.3.1",
"cerebral-baobab": "^0.4.5",
"cerebral-react": "^0.9.0",

@@ -37,4 +35,5 @@ "cerebral-router": "^0.8.0",

"webpack": "^1.5.3",
"webpack-dev-server": "^1.7.0"
"webpack-dev-server": "^1.7.0",
"cerebral-module-recorder": "^0.1.0"
}
}

@@ -1,5 +0,6 @@

# Cerebral [![Build Status](https://travis-ci.org/cerebral/cerebral.svg?branch=master)](https://travis-ci.org/cerebral/cerebral)
# Cerebral
A state controller with its own debugger
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebral/cerebral?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg?style=flat-square)](https://discord.gg/0kIweV4bd2bwwsvH)
[![Build Status](https://img.shields.io/travis/cerebral/cerebral/master.svg?style=flat-square)](https://travis-ci.org/cerebral/cerebral)

@@ -6,0 +7,0 @@ <img src="images/logo.png" width="300" align="center">

@@ -7,3 +7,8 @@ var utils = require('./utils.js');

var args = [].slice.call(arguments);
var path = args[0] ? Array.isArray(args[0]) ? args.shift() : [args.shift()] : [];
var path = [];
if (args[0] && Array.isArray(args[0])) {
path = args.shift();
} else if (args[0] && typeof args[0] === 'string') {
path = args.shift().split('.');
}
if (accessor === 'get' && typeof arguments[0] === 'function') {

@@ -38,4 +43,2 @@ return compute.getComputedValue(arguments[0]);

state.getComputed = compute.getComputedValue;
return state;

@@ -42,0 +45,0 @@ };

@@ -114,8 +114,9 @@ var utils = require('./utils.js');

var state = model.accessors.export && model.accessors.export();
var path = options.path || [];
var traversePath = path.slice();
while (traversePath.length) {
state = state[traversePath.shift()];
}
var paths = options.paths || [[]];
var state = paths.map(function (path) {
return {
path: path,
value: controller.get(path)
}
});

@@ -125,4 +126,3 @@ currentRecording = {

start: Date.now(),
signals: [],
path: path
signals: []
};

@@ -129,0 +129,0 @@

@@ -1,37 +0,67 @@

module.exports = function (controller) {
return function (modules) {
var utils = require('./utils.js');
module.exports = function (controller, model) {
var initialState = {};
var registerSignal = function (moduleName, name, chain) {
return controller.signal(moduleName + '.' + name, chain, {
modulePath: moduleName.split('.')
});
};
var registerSignalSync = function (moduleName, name, chain) {
return controller.signalSync(moduleName + '.' + name, chain, {
modulePath: moduleName.split('.')
});
};
var registerService = function (moduleName, name, service) {
utils.setDeep(controller.services, moduleName + '.' + name, service);
};
var registerInitialState = function (moduleName, state) {
utils.setDeep(initialState, moduleName, state);
model.mutators.set(moduleName.split('.'), state);
};
controller.on('reset', function () {
model.mutators.merge([], initialState);
});
return function registerModules (parentModuleName, modules) {
if (arguments.length === 1) {
modules = parentModuleName;
parentModuleName = null;
}
Object.keys(modules).forEach(function (moduleName) {
var module = modules[moduleName];
var signals = Object.keys(module.signals || {}).reduce(function (signals, key) {
if (Array.isArray(module.signals[key])) {
var signalName = moduleName + '.' + key;
signals[key] = controller.signal(signalName, module.signals[key]);
}
return signals;
}, {});
signals = Object.keys(module.signalsSync || {}).reduce(function (signals, key) {
if (Array.isArray(module.signalsSync[key])) {
var signalName = moduleName + '.' + key;
signals[key] = controller.signalSync(signalName, module.signalsSync[key]);
}
return signals;
}, signals);
controller.modules[moduleName] = {
var moduleConstructor = modules[moduleName];
var actualName = moduleName;
if (parentModuleName) {
moduleName = parentModuleName + '.' + moduleName;
}
var signals = utils.setDeep(controller.signals, moduleName, {});
var moduleExport = {
name: actualName,
path: moduleName.split('.')
};
var module = {
name: moduleName,
alias: function (alias) {
controller.modules[alias] = moduleExport;
},
signal: registerSignal.bind(null, moduleName),
signalSync: registerSignalSync.bind(null, moduleName),
service: registerService.bind(null, moduleName),
state: registerInitialState.bind(null, moduleName),
signals: signals,
services: module.services
registerModules: registerModules.bind(null, moduleName)
};
if (typeof module.init === 'function') {
var meta = module.init({
controller: controller,
name: moduleName,
signals: signals
});
if (typeof meta === 'object') {
Object.keys(meta).forEach(function (key) {
controller.modules[moduleName][key] = meta[key];
});
}
}
controller.services[moduleName] = controller.modules[moduleName].services;
var constructedModule = moduleConstructor(module, controller);
controller.modules[moduleName] = Object.keys(constructedModule || {}).reduce(function (module, key) {
module[key] = constructedModule[key];
return module;
}, moduleExport);
});

@@ -38,0 +68,0 @@ return controller.modules;

@@ -7,2 +7,3 @@ var utils = require('./utils.js');

var types = require('./types.js');
var createModulesArg = require('./createModulesArg.js');

@@ -15,3 +16,3 @@ var batchedSignals = [];

module.exports = function (signalStore, recorder, devtools, controller, model, services, compute) {
module.exports = function (signalStore, recorder, devtools, controller, model, services, compute, modules) {

@@ -23,2 +24,3 @@ return function () {

var defaultOptions = args[1] || {};
defaultOptions.modulePath = defaultOptions.modulePath || [];

@@ -176,2 +178,3 @@ var chain = args[0] || [];

var next = createNext.async(actionFunc);
var modulesArg = createModulesArg(modules, actionArgs[1], services);
actionFunc.call(null, {

@@ -181,3 +184,7 @@ input: actionArgs[0],

output: next.fn,
services: services
services: services,
modules: modulesArg,
module: defaultOptions.modulePath.reduce(function (modules, key) {
return modules[key];
}, modulesArg)
});

@@ -259,2 +266,3 @@

var next = createNext.sync(actionFunc, signal.name);
var modulesArg = createModulesArg(modules, actionArgs[1], services);
actionFunc.call(null, {

@@ -264,3 +272,7 @@ input: actionArgs[0],

output: next,
services: services
services: services,
modules: modulesArg,
module: defaultOptions.modulePath.reduce(function (exportedModule, key) {
return exportedModule[key];
}, modulesArg)
});

@@ -267,0 +279,0 @@

@@ -131,3 +131,3 @@ var utils = require('./utils.js');

window.addEventListener('cerebral.dev.logModel', function (event) {
console.log('CEREBRAL - model:', controller.get());
console.log('CEREBRAL - model:', controller.logModel());
});

@@ -134,0 +134,0 @@

@@ -17,3 +17,3 @@ var CreateSignalFactory = require('./CreateSignalFactory.js');

var signalStore = CreateSignalStore(signals, controller);
var modules = {};
services = services || {};

@@ -26,3 +26,3 @@

var recorder = CreateRecorder(signalStore, signals, controller, model);
var signalFactory = CreateSignalFactory(signalStore, recorder, devtools, controller, model, services, compute);
var signalFactory = CreateSignalFactory(signalStore, recorder, devtools, controller, model, services, compute, modules);
var signal = function () {

@@ -45,4 +45,5 @@ var signalNamePath = arguments[0].split('.');

}
controller.signals = signals;
controller.services = services;
controller.signals = signals;
controller.store = signalStore;

@@ -58,6 +59,9 @@ controller.recorder = recorder;

controller.devtools = devtools;
services.recorder = recorder;
controller.logModel = function () {
return model.logModel();
};
controller.recorder = recorder;
controller.modules = {};
controller.register = CreateRegisterModules(controller);
controller.modules = modules;
controller.registerModules = CreateRegisterModules(controller, model);

@@ -64,0 +68,0 @@ return controller;

@@ -91,3 +91,16 @@ var types = require('./types.js');

},
setDeep: function (object, stringPath, value) {
var path = stringPath.split('.');
var setKey = path.pop();
while (path.length) {
var key = path.shift();
object = object[key] = object[key] || {};
}
object[setKey] = object[setKey] ? Object.keys(object[setKey]).reduce(function (value, key) {
value[key] = object[setKey][key];
return value;
}, value) : value;
return value;
}
};

@@ -91,1 +91,29 @@ var Controller = require('./../src/index.js');

};
exports['should allow dot notation'] = function (test) {
var Model = function (state) {
return function (controller) {
return {
accessors: {
get: function (path) {
test.deepEqual(path, ['foo', 'bar']);
}
}
};
};
};
var ctrl = Controller(Model({}));
var signal = [
function (args) {
args.state.get(['foo', 'bar']);
args.state.get('foo.bar');
}
];
ctrl.signal('test', signal);
test.expect(2);
ctrl.signals.test.sync();
test.done()
};
var Controller = require('./../src/index.js');
var types = require('./../src/types.js');
var Model = function () {
var Model = function (initialState) {
var state = initialState;
return function () {
return {
accessors: {
get: function () {
return state;
}
},
mutators: {
set: function (path, value) {
var traverseState = state;
path = path.slice();
var setKey = path.pop();
while (path.length) {
var key = path.shift();
traverseState = traverseState[key] = traverseState[key] || {};
}
traverseState[setKey] = value;
}
}
};

@@ -13,9 +30,5 @@ };

exports['should be able to register a module'] = function (test) {
var ctrl = Controller(Model);
ctrl.register({
test: {
init: function () {
}
}
var ctrl = Controller(Model({}));
ctrl.registerModules({
test: function () {}
});

@@ -26,14 +39,14 @@ test.ok(ctrl.modules.test);

exports['should pass the controller its name and its signals to the init method'] = function (test) {
var ctrl = Controller(Model);
test.expect(3);
ctrl.register({
test: {
init: function (args) {
test.equal(args.controller, ctrl);
test.equal(args.name, 'test');
test.deepEqual(args.signals, {});
}
exports['should pass the module and controller, and expose module name and path on controller'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(5);
ctrl.registerModules({
test: function (module, controller) {
test.equal(controller, ctrl);
test.equal(module.name, 'test');
test.deepEqual(module.signals, {});
}
});
test.equal(ctrl.modules.test.name, 'test');
test.deepEqual(ctrl.modules.test.path, ['test']);
test.done();

@@ -43,48 +56,104 @@ };

exports['should be able to add a signal'] = function (test) {
var ctrl = Controller(Model);
ctrl.register({
test: {
init: function () {},
signals: {
test: []
}
var ctrl = Controller(Model({}));
ctrl.registerModules({
test: function (module) {
module.signal('test', []);
module.signalSync('test2', []);
}
});
test.ok(ctrl.modules.test.signals.test);
test.ok(ctrl.signals.test.test);
test.ok(ctrl.signals.test.test2);
test.done();
};
exports['should be able to add a sync signal'] = function (test) {
var ctrl = Controller(Model);
ctrl.register({
test: {
init: function () {},
signals: {
test: []
},
signalsSync: {
testSync: []
}
exports['should be able to add a service'] = function (test) {
var ctrl = Controller(Model({}));
ctrl.registerModules({
test: function (module) {
module.service('test', {});
}
});
test.ok(ctrl.modules.test.signals.test);
test.ok(ctrl.signals.test.test);
test.ok(ctrl.modules.test.signals.testSync);
test.ok(ctrl.signals.test.test);
test.ok(ctrl.services.test.test);
test.done();
};
exports['should be able to add a service'] = function (test) {
var ctrl = Controller(Model);
ctrl.register({
test: {
init: function () {},
services: {
method: function () {}
}
exports['should expose module on actions running on a module signal'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(1);
ctrl.registerModules({
test: function (module) {
module.signal('test', [
function action (arg) {
test.ok(arg.module);
}
])
}
});
test.ok(ctrl.services.test.method);
ctrl.signals.test.test.sync();
test.done();
};
exports['should expose modules on all actions'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(1);
ctrl.signal('test', [
function action (arg) {
test.ok(arg.modules.test);
}
])
ctrl.registerModules({
test: function () {}
});
ctrl.signals.test.sync();
test.done();
};
exports['should be able to add namespaced state'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(1);
ctrl.registerModules({
test: function (module) {
module.state({
foo: 'bar'
});
}
});
test.deepEqual(ctrl.get(), {test: {foo: 'bar'}});
test.done();
};
exports['should be able to add an alias'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(2);
ctrl.registerModules({
test: function (module) {
module.alias('cerebral-module-test');
}
});
test.ok(ctrl.modules['cerebral-module-test']);
test.ok(ctrl.modules.test);
test.done();
};
exports['should be able to add a submodule with namespaced state, signals and services'] = function (test) {
var ctrl = Controller(Model({}));
test.expect(2);
ctrl.registerModules({
test: function (module) {
module.registerModules({
sub: function (module) {
module.signal('test', [
function action (arg) {
test.ok(arg.modules.test.sub.services.test);
test.deepEqual(arg.state.get(), {test: {sub: {foo: 'bar'} } });
}
]);
module.service('test', {});
module.state({foo: 'bar'});
}
});
}
});
ctrl.signals.test.sub.test.sync();
test.done();
};

@@ -57,9 +57,12 @@ var Controller = require('./../src/index.js');

return function (controller) {
controller.on('seek', function (seek, currentRecording) {
state = currentRecording.initialState;
controller.on('seek', function (seek, recording) {
state = initialState;
});
return {
accessors: {
export: function () {
get: function () {
return state;
},
merge: function () {
return state;
}

@@ -95,3 +98,8 @@ },

setTimeout(function () {
try{
ctrl.recorder.seek(0);
} catch (e) {
console.log(e.stack);
}
ctrl.recorder.play();

@@ -116,9 +124,12 @@ test.deepEqual(state, {});

return function (controller) {
controller.on('seek', function (seek, currentRecording) {
state = currentRecording.initialState;
controller.on('seek', function (seek, recording) {
state = initialState;
});
return {
accessors: {
export: function () {
get: function () {
return state;
},
merge: function () {
return state;
}

@@ -169,9 +180,12 @@ },

return function (controller) {
controller.on('seek', function (seek, currentRecording) {
state = currentRecording.initialState;
controller.on('seek', function (seek, recording) {
state = initialState;
});
return {
accessors: {
export: function () {
get: function () {
return state;
},
merge: function () {
return state;
}

@@ -234,9 +248,12 @@ },

return function (controller) {
controller.on('seek', function (seek, currentRecording) {
state = currentRecording.initialState;
controller.on('seek', function (seek, recording) {
state = initialState;
});
return {
accessors: {
export: function () {
get: function () {
return state;
},
merge: function () {
return state;
}

@@ -243,0 +260,0 @@ },

@@ -533,3 +533,3 @@ var Controller = require('./../src/index.js');

exports['should allow services and have recorder by default'] = function (test) {
exports['should allow services'] = function (test) {
var ctrl = Controller(Model(), {

@@ -541,3 +541,2 @@ foo: 'bar'

test.ok(args.services.foo);
test.ok(args.services.recorder);
test.done();

@@ -544,0 +543,0 @@ }

@@ -209,2 +209,5 @@ var Controller = require('./../src/index.js');

state[path.pop()] = value;
},
merge: function (path, value) {
state = {};
}

@@ -259,2 +262,5 @@ }

state[path.pop()] = value;
},
merge: function (path, value) {
state = {};
}

@@ -261,0 +267,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc