Comparing version 0.8.6 to 0.9.0
@@ -8,8 +8,13 @@ 'use strict'; | ||
var _Pipeline = require('./Pipeline'); | ||
var _Processor = require('./Processor'); | ||
var _Processor2 = _interopRequireDefault(_Processor); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function Element(func, props, children) { | ||
return { | ||
id: (0, _utils.getId)(), | ||
func: func, | ||
@@ -21,6 +26,7 @@ props: props, | ||
scope: {}, | ||
pipeline: undefined, | ||
processor: undefined, | ||
result: undefined, | ||
context: undefined, | ||
parent: undefined, | ||
debug: undefined, | ||
@@ -37,3 +43,3 @@ mergeToProps: function mergeToProps(additionalProps) { | ||
}, | ||
readFromScope: function readFromScope(key) { | ||
readFromScope: function readFromScope(key, requester) { | ||
var scope = this.scope, | ||
@@ -45,3 +51,3 @@ parent = this.parent; | ||
if (typeof value !== 'undefined') return value; | ||
return parent.readFromScope(key); | ||
return parent.readFromScope(key, requester); | ||
}, | ||
@@ -54,9 +60,16 @@ run: async function run(parent) { | ||
this.context = parent.context; | ||
this.pipeline = this.func.pipeline || (0, _Pipeline.createDefaultPipeline)(this); | ||
if (!this.processor) { | ||
this.processor = (0, _Processor2.default)(this, this.func.processor); | ||
} | ||
if (typeof func === 'string') { | ||
this.func = this.context[func]; | ||
if (this.context[func]) { | ||
this.func = this.context[func]; | ||
} else { | ||
throw new Error('"' + func + '" is missing in the context.'); | ||
} | ||
} | ||
return await this.pipeline.process(); | ||
return await this.processor(); | ||
} | ||
@@ -67,5 +80,2 @@ }; | ||
// Static | ||
Element.isItAnElement = function (element) { | ||
return element && !!element.run; | ||
}; | ||
Element.createRootElement = function (context) { | ||
@@ -76,3 +86,3 @@ return { | ||
dispatch: function dispatch() {}, | ||
readFromScope: function readFromScope(key) { | ||
readFromScope: function readFromScope(key, requester) { | ||
var value = this.scope[key]; | ||
@@ -84,9 +94,6 @@ if (typeof value !== 'undefined') return value; | ||
throw new Error('Undefined variable "' + key + '".'); | ||
requester = requester === '' ? 'unknown' : requester; | ||
throw new Error('Undefined variable "' + key + '" requested by <' + requester + '>.'); | ||
} | ||
}; | ||
}; | ||
Element.errors = { | ||
STOP_PROCESSING: 'STOP_PROCESSING', | ||
CONTINUE_PROCESSING: 'CONTINUE_PROCESSING' | ||
}; |
@@ -12,9 +12,16 @@ 'use strict'; | ||
var _execute = require('../../middlewares/execute'); | ||
var _execute2 = _interopRequireDefault(_execute); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function Inspect(props) { | ||
function Inspect(_ref) { | ||
var children = _ref.children; | ||
var inspection = { | ||
numOfSubscribes: _Integration2.default._listeners.length | ||
}; | ||
this.pipeline('children', inspection); | ||
} | ||
children(inspection); | ||
} | ||
Inspect.processor = [_execute2.default]; |
@@ -11,10 +11,8 @@ 'use strict'; | ||
var _Element = require('../../Element'); | ||
var _utils = require('../../utils'); | ||
var _Element2 = _interopRequireDefault(_Element); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = async function Select(props) { | ||
if (props && _Element2.default.isItAnElement(props.selector)) { | ||
if (props && (0, _utils.isItAnElement)(props.selector)) { | ||
var s = await props.selector.run(this); | ||
@@ -21,0 +19,0 @@ return s(_Integration2.default.getState()); |
@@ -11,14 +11,16 @@ 'use strict'; | ||
var _execute = require('../../middlewares/execute'); | ||
var _execute2 = _interopRequireDefault(_execute); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = async function Subscribe(props) { | ||
var _this = this; | ||
async function Subscribe(_ref) { | ||
var children = _ref.children, | ||
type = _ref.type; | ||
this.pipeline.disable('result'); | ||
this.pipeline.disable('children'); | ||
if (props && props.type) { | ||
if (type) { | ||
_Integration2.default.addListener(function (action) { | ||
if (action.type === props.type) { | ||
_this.pipeline('result', action); | ||
_this.pipeline('children', action); | ||
if (action.type === type) { | ||
children(action); | ||
} | ||
@@ -29,2 +31,5 @@ }); | ||
} | ||
}; | ||
} | ||
Subscribe.processor = [_execute2.default]; | ||
exports.default = Subscribe; |
@@ -6,3 +6,2 @@ 'use strict'; | ||
}); | ||
exports.default = SubscribeOnce; | ||
@@ -13,14 +12,16 @@ var _Integration = require('./Integration'); | ||
var _execute = require('../../middlewares/execute'); | ||
var _execute2 = _interopRequireDefault(_execute); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function SubscribeOnce(props) { | ||
var _this = this; | ||
function SubscribeOnce(_ref) { | ||
var children = _ref.children, | ||
type = _ref.type; | ||
this.pipeline.disable('result'); | ||
this.pipeline.disable('children'); | ||
if (props && props.type) { | ||
if (type) { | ||
var removeListener = _Integration2.default.addListener(function (action) { | ||
if (action.type === props.type) { | ||
_this.pipeline('result', action); | ||
_this.pipeline('children', action); | ||
if (action.type === type) { | ||
children(action); | ||
removeListener(); | ||
@@ -30,4 +31,7 @@ } | ||
} else { | ||
throw new Error('<Subscribe> requires `type` prop.'); | ||
throw new Error('<SubscribeOnce> requires `type` prop.'); | ||
} | ||
} | ||
} | ||
SubscribeOnce.processor = [_execute2.default]; | ||
exports.default = SubscribeOnce; |
@@ -6,10 +6,6 @@ 'use strict'; | ||
}); | ||
exports.Redux = exports.Pipeline = exports.Parallel = exports.run = exports.A = undefined; | ||
exports.Redux = exports.Processor = exports.run = exports.A = undefined; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _Parallel = require('./elements/Parallel'); | ||
var _Parallel2 = _interopRequireDefault(_Parallel); | ||
var _redux = require('./elements/redux'); | ||
@@ -19,6 +15,14 @@ | ||
var _Pipeline = require('./Pipeline'); | ||
var _execute = require('./middlewares/execute'); | ||
var _Pipeline2 = _interopRequireDefault(_Pipeline); | ||
var _execute2 = _interopRequireDefault(_execute); | ||
var _result = require('./middlewares/result'); | ||
var _result2 = _interopRequireDefault(_result); | ||
var _children = require('./middlewares/children'); | ||
var _children2 = _interopRequireDefault(_children); | ||
var _Element = require('./Element'); | ||
@@ -28,6 +32,8 @@ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function create(func, props) { | ||
@@ -49,2 +55,3 @@ for (var _len = arguments.length, children = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
} | ||
async function run(element) { | ||
@@ -55,4 +62,4 @@ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (_Element2.default.isItAnElement(element)) { | ||
if (_Element2.default.isItAnElement(element.func)) { | ||
if ((0, _utils.isItAnElement)(element)) { | ||
if ((0, _utils.isItAnElement)(element.func)) { | ||
element.func.mergeToProps(element.props); | ||
@@ -67,2 +74,3 @@ return await element.func.run(rootElement); | ||
var Redux = _extends({}, ReduxMethods); | ||
var Processor = { execute: _execute2.default, result: _result2.default, children: _children2.default }; | ||
var A = create; | ||
@@ -72,4 +80,3 @@ | ||
exports.run = run; | ||
exports.Parallel = _Parallel2.default; | ||
exports.Pipeline = _Pipeline2.default; | ||
exports.Processor = Processor; | ||
exports.Redux = Redux; |
@@ -9,26 +9,18 @@ 'use strict'; | ||
var _Element = require('../Element'); | ||
var _constants = require('../constants'); | ||
var _Element2 = _interopRequireDefault(_Element); | ||
var _children = require('./children'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _children2 = _interopRequireDefault(_children); | ||
var handleElementError = async function handleElementError(error, props, element) { | ||
if (props && props.onError) { | ||
props.onError.mergeToProps({ error: error }); | ||
var _exports = require('./exports'); | ||
var onErrorStrategy = await props.onError.run(element); | ||
var _exports2 = _interopRequireDefault(_exports); | ||
if (onErrorStrategy === true) { | ||
throw new Error(_Element2.default.errors.CONTINUE_PROCESSING); | ||
} | ||
throw new Error(_Element2.default.errors.STOP_PROCESSING); | ||
} else { | ||
throw error; | ||
} | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = async function execute(element) { | ||
async function executeMiddleware(element) { | ||
var func = element.func, | ||
props = element.props; | ||
props = element.props, | ||
name = element.name; | ||
@@ -43,3 +35,3 @@ var normalizedProps = _extends({}, props); | ||
var prop = propName.substr(1, propName.length); | ||
var value = element.readFromScope(prop); | ||
var value = element.readFromScope(prop, name); | ||
@@ -60,8 +52,15 @@ if (typeof value !== 'undefined') { | ||
// creating the `children` prop | ||
normalizedProps.children = function (result) { | ||
element.result = result; | ||
(0, _exports2.default)(element); | ||
(0, _children2.default)(element); | ||
}; | ||
// actual running of the function | ||
try { | ||
element.result = await func.call(element, normalizedProps); | ||
} catch (error) { | ||
await handleElementError(error, normalizedProps, element); | ||
} | ||
}; | ||
element.result = await func.call(element, normalizedProps); | ||
} | ||
executeMiddleware._name = 'EXECUTE'; | ||
exports.default = executeMiddleware; |
@@ -12,2 +12,4 @@ 'use strict'; | ||
ret = ret.substr(0, ret.indexOf('(')); | ||
if (ret === '') return 'unknown'; | ||
return ret; | ||
@@ -21,2 +23,11 @@ }; | ||
return scoped; | ||
}; | ||
var isItAnElement = exports.isItAnElement = function isItAnElement(element) { | ||
return element && !!element.run; | ||
}; | ||
var ids = 100; | ||
var getId = exports.getId = function getId() { | ||
return ids++; | ||
}; |
{ | ||
"name": "actml", | ||
"version": "0.8.6", | ||
"version": "0.9.0", | ||
"description": "Like jsx but for your business logic", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
@@ -423,3 +423,3 @@ # <ActML /> :rocket: <!-- omit in toc --> | ||
We will see `B` followed by `C` but not `Z` because there's an error at that level. | ||
We will see `B` followed by `C` but not `Z` because there's an error at that level. Here is a [Codesandbox](https://codesandbox.io/s/qlpwp2nn06) with an example. | ||
@@ -426,0 +426,0 @@ ## Examples |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
376329
29
739