Comparing version 0.3.1 to 0.3.2
@@ -6,116 +6,21 @@ "use strict"; | ||
}); | ||
exports.initConfig = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _events = require("events"); | ||
var _utils = require("./utils"); | ||
var _plugins = require("./plugins"); | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
Object.keys(_plugins).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins[key]; | ||
} | ||
}); | ||
}); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _menhera = require("./menhera"); | ||
var initConfig = exports.initConfig = { | ||
lifeCycle: ["_awake", "start"], | ||
components: [_plugins.INIT] | ||
}; | ||
var _menhera2 = _interopRequireDefault(_menhera); | ||
var Menhera = function () { | ||
function Menhera() { | ||
_classCallCheck(this, Menhera); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
this.components = {}; | ||
this.hooks = {}; | ||
this.config = {}; | ||
} | ||
_createClass(Menhera, [{ | ||
key: "init", | ||
value: function init(config) { | ||
var _this = this; | ||
var _ = this; | ||
_.config = (0, _utils.ConfigMerger)(initConfig, config); | ||
var _$config = _.config, | ||
_$config$components = _$config.components, | ||
components = _$config$components === undefined ? {} : _$config$components, | ||
_$config$lifeCycle = _$config.lifeCycle, | ||
lifeCycle = _$config$lifeCycle === undefined ? [] : _$config$lifeCycle; | ||
components.forEach(function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(component) { | ||
var cp, name; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
cp = typeof component === "function" ? component({ _: _ }) : component; | ||
name = cp.name; | ||
_.components[name] = cp; | ||
lifeCycle.forEach(function (key) { | ||
if (key.startsWith("_")) { | ||
cp[key] && cp[key](); | ||
} | ||
}); | ||
_context.next = 6; | ||
return Object.keys(cp).forEach(function (_key) { | ||
if (_key.startsWith("_")) { | ||
var hook = _.hooks[_key]; | ||
if (Array.isArray(hook)) { | ||
hook.forEach(function (h) { | ||
(0, _utils.bindHook)({ _: _, hook: h, _key: _key, cp: cp }); | ||
}); | ||
} else { | ||
(0, _utils.bindHook)({ _: _, hook: hook, _key: _key, cp: cp }); | ||
} | ||
} | ||
}); | ||
case 6: | ||
_context.next = 8; | ||
return Object.keys(cp).forEach(function (_key) { | ||
if (!_key.startsWith("_")) { | ||
var hook = _["hooks"][_key]; | ||
if (Array.isArray(hook)) { | ||
hook.forEach(function (h) { | ||
(0, _utils.bindHook)({ hook: h, _key: _key, cp: cp }); | ||
}); | ||
} else { | ||
(0, _utils.bindHook)({ hook: hook, _key: _key, cp: cp }); | ||
} | ||
} | ||
}); | ||
case 8: | ||
lifeCycle.forEach(function (key) { | ||
if (!key.startsWith("_")) { | ||
cp[key] && cp[key](); | ||
} | ||
}); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
}]); | ||
return Menhera; | ||
}(); | ||
exports.default = Menhera; | ||
exports.default = _menhera2.default; |
@@ -9,8 +9,8 @@ "use strict"; | ||
var INIT = exports.INIT = function INIT(_ref) { | ||
var v0 = exports.v0 = function v0(_ref) { | ||
var _ = _ref._; | ||
return { | ||
name: "INIT", | ||
name: "v0", | ||
_awake: function _awake() { | ||
_.hooks._hooks = function (_ref2) { | ||
_.hooks._hooks = [function (_ref2) { | ||
var key = _ref2.key, | ||
@@ -26,8 +26,17 @@ val = _ref2.val, | ||
} | ||
}; | ||
_.hooks._methods = function (_ref3) { | ||
var key = _ref3.key, | ||
val = _ref3.val, | ||
cp = _ref3.cp; | ||
}]; | ||
} | ||
}; | ||
}; | ||
var v1 = exports.v1 = function v1(_ref3) { | ||
var _ = _ref3._; | ||
return { | ||
name: "v1", | ||
_hooks: { | ||
_methods: function _methods(_ref4) { | ||
var key = _ref4.key, | ||
val = _ref4.val, | ||
cp = _ref4.cp; | ||
if (!cp[key]) { | ||
@@ -38,6 +47,6 @@ cp[key] = val; | ||
} | ||
}; | ||
_.hooks._data = function (_ref4) { | ||
var _val = _ref4._val, | ||
cp = _ref4.cp; | ||
}, | ||
_data: function _data(_ref5) { | ||
var _val = _ref5._val, | ||
cp = _ref5.cp; | ||
@@ -51,8 +60,8 @@ var props = _val(); | ||
for (var _iterator = Object.entries(props)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref5 = _step.value; | ||
var _ref6 = _step.value; | ||
var _ref6 = _slicedToArray(_ref5, 2); | ||
var _ref7 = _slicedToArray(_ref6, 2); | ||
var key = _ref6[0]; | ||
var val = _ref6[1]; | ||
var key = _ref7[0]; | ||
var val = _ref7[1]; | ||
@@ -79,5 +88,5 @@ if (!cp[key]) { | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
}; |
{ | ||
"name": "menhera", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "dist", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -11,3 +11,3 @@ # Menhera | ||
import { EventEmitter } from "events"; | ||
import Menhera from "menhera"; | ||
import Menhera, { v1 } from "menhera"; | ||
import minimist from "minimist"; | ||
@@ -49,4 +49,4 @@ | ||
"*": { | ||
help() { | ||
console.log("* help"); | ||
exec() { | ||
console.log("help"); | ||
} | ||
@@ -64,4 +64,4 @@ }, | ||
// lifeCycle: ["_awake", "start"], | ||
components: [CLI, cliTest] | ||
components: [v1, CLI, cliTest] | ||
}); | ||
``` |
13328
6
255