Comparing version 0.26.1 to 0.27.0
@@ -1,5 +0,5 @@ | ||
function setFilter (args, state) { | ||
state.set('filter', args.route.params.filter); | ||
function setFilter (input, state) { | ||
state.set('filter', input.filter); | ||
}; | ||
export default setFilter; |
@@ -37,9 +37,9 @@ import React from 'react'; | ||
<li> | ||
<a className={this.renderRouteClass('all')} href="#/">All</a> | ||
<a className={this.renderRouteClass('all')} onClick={() => this.props.signals.allTodosClicked()}>All</a> | ||
</li> | ||
<li> | ||
<a className={this.renderRouteClass('active')} href="#/active">Active</a> | ||
<a className={this.renderRouteClass('active')} onClick={() => this.props.signals.filterClicked({filter: 'active'})}>Active</a> | ||
</li> | ||
<li> | ||
<a className={this.renderRouteClass('completed')} href="#/completed">Completed</a> | ||
<a className={this.renderRouteClass('completed')} onClick={() => this.props.signals.filterClicked({filter: 'completed'})}>Completed</a> | ||
</li> | ||
@@ -46,0 +46,0 @@ </ul> |
@@ -43,3 +43,3 @@ import './../node_modules/todomvc-common/base.css'; | ||
// ROUTER | ||
const router = CerebralRouter(controller, { | ||
CerebralRouter(controller, { | ||
'/': 'allTodosClicked', | ||
@@ -50,3 +50,3 @@ '/:filter': 'filterClicked' | ||
baseUrl: '/todomvc/' | ||
}).trigger(); | ||
}); | ||
@@ -53,0 +53,0 @@ // RENDER |
{ | ||
"name": "cerebral", | ||
"version": "0.26.1", | ||
"version": "0.27.0", | ||
"description": "A state controller with its own debugger", | ||
@@ -19,4 +19,4 @@ "main": "src/index.js", | ||
"cerebral-baobab": "^0.3.1", | ||
"cerebral-react": "^0.2.0", | ||
"cerebral-router": "^0.7.0", | ||
"cerebral-react": "^0.8.0", | ||
"cerebral-router": "^0.8.0", | ||
"classnames": "^2.1.1", | ||
@@ -23,0 +23,0 @@ "css-loader": "^0.9.1", |
@@ -1,5 +0,5 @@ | ||
# Cerebral [![Build Status](https://travis-ci.org/christianalfoni/cerebral.svg?branch=master)](https://travis-ci.org/christianalfoni/cerebral) | ||
# Cerebral [![Build Status](https://travis-ci.org/cerebral/cerebral.svg?branch=master)](https://travis-ci.org/cerebral/cerebral) | ||
A state controller with its own debugger | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/christianalfoni/cerebral?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebral/cerebral?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
@@ -9,3 +9,3 @@ <img src="images/logo.png" width="300" align="center"> | ||
## The Cerebral Webpage is now launched | ||
You can access the webpage at [http://christianalfoni.com/cerebral/](http://christianalfoni.com/cerebral/). You will find all the information you need there. | ||
You can access the webpage at [http://www.cerebraljs.com/](http://www.cerebraljs.com/). You will find all the information you need there. | ||
@@ -12,0 +12,0 @@ - [How to create a custom Cerebral VIEW package](#how-to-create-a-custom-cerebral-view-package) |
@@ -65,2 +65,12 @@ var utils = require('./utils.js'); | ||
} else if (!Array.isArray(action) && typeof action === 'object' && typeof action !== null) { | ||
var prevAction = actions[index - 1]; | ||
Object.keys(action).forEach(function (key) { | ||
if (!Array.isArray(action[key])) { | ||
throw new Error([ | ||
'Cerebral: The paths for action "' + utils.getFunctionName(prevAction) + | ||
'" in signal "' + signalName + '" are not valid. They have to be an array"' | ||
].join('')); | ||
} | ||
}) | ||
} | ||
@@ -67,0 +77,0 @@ } |
@@ -20,9 +20,6 @@ var utils = require('./utils.js'); | ||
var signalName = args.shift(); | ||
var defaultOptions = args[1] || {}; | ||
if (args.length > 1 || typeof args[0] === 'function') { | ||
console.warn('Cerebral - DEPRECATED signal definition with arguments. A signal is now defined with an array. This will lower threshold of readability for new devs using Cerebral'); | ||
} | ||
var chain = args[0] || []; | ||
var chain = args.length === 1 && Array.isArray(args[0]) ? args[0] : args; | ||
if (utils.isDeveloping()) { | ||
@@ -53,3 +50,3 @@ analyze(signalName, chain); | ||
var runSync = options.isSync; | ||
var runSync = defaultOptions.isSync || options.isSync; | ||
@@ -223,3 +220,2 @@ // When remembering, the branches with filled out values will be | ||
} else { | ||
if (signalStore.isRemembering()) { | ||
@@ -269,3 +265,2 @@ | ||
if (result.path) { | ||
@@ -281,2 +276,7 @@ action.outputPath = result.path; | ||
} | ||
} else if (result.then) { | ||
return result.then(function () { | ||
controller.emit('actionEnd'); | ||
return runBranch(branch, index + 1, start); | ||
}); | ||
} else { | ||
@@ -323,3 +323,2 @@ controller.emit('actionEnd'); | ||
}; | ||
signalChain.chain = chain; | ||
@@ -329,2 +328,3 @@ signalChain.sync = function (payload) { | ||
}; | ||
signalChain.signalName = signalName; | ||
@@ -331,0 +331,0 @@ return signalChain; |
@@ -25,4 +25,3 @@ var CreateSignalFactory = require('./CreateSignalFactory.js'); | ||
var signalFactory = CreateSignalFactory(signalStore, recorder, devtools, controller, model, services, compute); | ||
controller.signal = function () { | ||
var signal = function () { | ||
var signalNamePath = arguments[0].split('.'); | ||
@@ -35,5 +34,11 @@ var signalName = signalNamePath.pop(); | ||
} | ||
signalMethodPath[signalName] = signalFactory.apply(null, arguments); | ||
return signalMethodPath[signalName] = signalFactory.apply(null, arguments); | ||
}; | ||
controller.signal = signal; | ||
controller.signalSync = function () { | ||
var defaultOptions = arguments[2] || {}; | ||
defaultOptions.isSync = true; | ||
return signal.apply(null, [arguments[0], arguments[1], defaultOptions]) | ||
} | ||
controller.services = services; | ||
@@ -53,2 +58,17 @@ controller.signals = signals; | ||
controller.extends = function (modules) { | ||
var meta = {}; | ||
Object.keys(modules).forEach(function (moduleName) { | ||
var module = modules[moduleName]; | ||
Object.keys(module).forEach(function (key) { | ||
if (key === 'init') { | ||
meta[moduleName] = module[key](controller, moduleName); | ||
} else { | ||
controller.signal(moduleName + '.' + key, module[key]); | ||
} | ||
}); | ||
}); | ||
return meta; | ||
}; | ||
return controller; | ||
@@ -55,0 +75,0 @@ }; |
@@ -5,8 +5,9 @@ var Controller = require('./../src/index.js'); | ||
}; | ||
var Model = function () { | ||
var Model = function (state) { | ||
state = state || {}; | ||
return function () { | ||
return { | ||
accessors: { | ||
get: function () { | ||
get: function (path) { | ||
return state[path[0]]; | ||
} | ||
@@ -16,3 +17,2 @@ }, | ||
set: function (path, value) { | ||
state = {}; | ||
state[path.pop()] = value; | ||
@@ -25,6 +25,9 @@ } | ||
exports['should run sync signals'] = function (test) { | ||
exports['should register signals'] = function (test) { | ||
var ctrl = Controller(Model()); | ||
ctrl.signal('test'); | ||
var signal = ctrl.signal('test'); | ||
test.ok(typeof ctrl.signals.test === 'function'); | ||
test.ok(signal); | ||
console.log(signal); | ||
test.equal(signal.signalName, 'test'); | ||
test.done(); | ||
@@ -42,6 +45,6 @@ }; | ||
var ctrl = Controller(Model()); | ||
ctrl.signal('test', function () { | ||
ctrl.signal('test', [function () { | ||
test.ok(true); | ||
test.done(); | ||
}); | ||
}]); | ||
ctrl.signals.test(); | ||
@@ -566,2 +569,17 @@ }; | ||
exports['should trigger signal synchronously when defined as signalSync'] = function (test) { | ||
var ctrl = Controller(Model()); | ||
var hasRun = false; | ||
var signal = [ | ||
function () { | ||
hasRun = true; | ||
} | ||
]; | ||
ctrl.signalSync('test', signal); | ||
ctrl.signals.test(); | ||
test.ok(hasRun); | ||
test.done(); | ||
}; | ||
exports['should throw error when input is defined on action and value is missing or is wrong type'] = function (test) { | ||
@@ -637,32 +655,18 @@ var ctrl = Controller(Model()); | ||
/* Not sure how to test async throws | ||
exports['should throw running output async in sync flow'] = function (test) { | ||
exports['should throw error when output path is not an array'] = function (test) { | ||
var ctrl = Controller(Model()); | ||
var action = function (input, state, output) { | ||
async(output); | ||
output.success(); | ||
}; | ||
ctrl.signal('test', action); | ||
test.throws(function () { | ||
ctrl.signals.test.sync(); | ||
}); | ||
async(test.done); | ||
}; | ||
*/ | ||
exports['should allow signals as arrays'] = function (test) { | ||
var ctrl = Controller(Model()); | ||
var action = function (input, state, output) { | ||
test.ok(true); | ||
}; | ||
var signal = [ | ||
[ | ||
action | ||
action, { | ||
success: function () {} | ||
} | ||
] | ||
]; | ||
ctrl.signal('test', signal); | ||
test.expect(1); | ||
ctrl.signals.test.sync(); | ||
test.throws(function () { | ||
ctrl.signal('test', signal); | ||
}); | ||
test.done(); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4352778
48354
6