Comparing version 0.0.8 to 0.0.9
@@ -27,2 +27,4 @@ "use strict"; | ||
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"); }); }; } | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
@@ -41,3 +43,3 @@ | ||
this.structs = {}; | ||
this.components = {}; | ||
this.config = (0, _utils.ConfigMerger)(initConfig, config); | ||
@@ -51,6 +53,7 @@ } | ||
var _config = this.config, | ||
_config$components = _config.components, | ||
components = _config$components === undefined ? [] : _config$components, | ||
lifeCycle = _config.lifeCycle; | ||
var _ = this; | ||
var _$config = _.config, | ||
_$config$components = _$config.components, | ||
components = _$config$components === undefined ? [] : _$config$components, | ||
lifeCycle = _$config.lifeCycle; | ||
@@ -61,56 +64,81 @@ var _lifeCycle = _toArray(lifeCycle), | ||
components.forEach(function (comp) { | ||
var struct = (0, _utils.typeParser)({ | ||
obj: comp | ||
}); | ||
var name = struct.props.name, | ||
events = struct.events; | ||
components.forEach(function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(comp) { | ||
var name; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
name = comp.name; | ||
_this.structs[name] = struct; | ||
events[awake] && events[awake].call(_this); | ||
}); | ||
_.components[name] = comp; | ||
Object.values(this.structs).forEach(function (struct) { | ||
var props = struct.props, | ||
events = struct.events; | ||
_context.t0 = comp[awake]; | ||
if (!_context.t0) { | ||
_context.next = 6; | ||
break; | ||
} | ||
Object.keys(props).forEach(function (prop) { | ||
if (typeof _this[prop] === "function") { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
_context.next = 6; | ||
return comp[awake]({ _: _ }); | ||
try { | ||
for (var _iterator = Object.entries(props[prop])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref = _step.value; | ||
case 6: | ||
_context.next = 8; | ||
return Object.keys(comp).forEach(function (prop) { | ||
if (typeof _[prop] === "function") { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
try { | ||
for (var _iterator = Object.entries(comp[prop])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref2 = _step.value; | ||
var key = _ref2[0]; | ||
var value = _ref2[1]; | ||
var _ref3 = _slicedToArray(_ref2, 2); | ||
_this[prop].call(_this, key, value); | ||
var _name = _ref3[0]; | ||
var value = _ref3[1]; | ||
if (typeof value === "function") { | ||
_[prop]({ _: _, name: _name, event: value }); | ||
} else { | ||
_[prop]({ _: _, name: _name, props: value }); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
case 8: | ||
lifeCycles.forEach(function (key) { | ||
comp[key] && comp[key]({ _: _ }); | ||
}); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}, _callee, _this); | ||
})); | ||
lifeCycles.forEach(function (key) { | ||
events[key] && events[key].call(_this); | ||
}); | ||
}); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
@@ -117,0 +145,0 @@ }]); |
@@ -6,14 +6,17 @@ "use strict"; | ||
}); | ||
exports.Event = exports.Observer = undefined; | ||
exports.CLI = exports.Event = exports.Observer = undefined; | ||
var _events = require("events"); | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
var Observer = exports.Observer = { | ||
name: "observer", | ||
awake: function awake() { | ||
this.Observer = new _events.EventEmitter(); | ||
this.state = {}; | ||
this._state = {}; | ||
var _this = this; | ||
this.state = new Proxy(this._state, { | ||
name: "menhera-observer", | ||
awake: function awake(_ref) { | ||
var _ = _ref._; | ||
_.Observer = { Event: new _events.EventEmitter() }; | ||
_.state = {}; | ||
_._state = {}; | ||
_.state = new Proxy(_._state, { | ||
get: function get(target, key) { | ||
@@ -29,9 +32,18 @@ if (key in target) { | ||
target[key] = val; | ||
_this.Observer.emit(key, val); | ||
_.Observer.Event.emit(key, { _: _, val: val }); | ||
return true; | ||
} | ||
}); | ||
this.observer = function (name, fn) { | ||
_this.Observer.on(name, fn); | ||
_.observer = function (_ref2) { | ||
var name = _ref2.name, | ||
event = _ref2.event; | ||
_.Observer.Event.on(name, event); | ||
}; | ||
}, | ||
observer: { | ||
foo: function foo() { | ||
console.log("bar"); | ||
} | ||
} | ||
@@ -41,23 +53,69 @@ }; | ||
var Event = exports.Event = { | ||
name: "event", | ||
awake: function awake() { | ||
var _this2 = this; | ||
name: "menhera-event", | ||
awake: function awake(_ref3) { | ||
var _ = _ref3._; | ||
this.Event = new _events.EventEmitter(); | ||
this.on = function (name, fn) { | ||
_this2.Event.on(name, fn); | ||
return _this2; | ||
_.Event = new _events.EventEmitter(); | ||
_.on = function (_ref4) { | ||
var name = _ref4.name, | ||
event = _ref4.event; | ||
_.Event.on(name, event); | ||
return _; | ||
}; | ||
this.emit = function (name) { | ||
var _Event; | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
_.emit = function (name) { | ||
for (var _len = arguments.length, val = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
val[_key - 1] = arguments[_key]; | ||
} | ||
(_Event = _this2.Event).emit.apply(_Event, [name].concat(args)); | ||
return _this2; | ||
_.Event.emit(name, { _: _, val: val }); | ||
return _; | ||
}; | ||
}, | ||
on: { | ||
foo: function foo() { | ||
console.log("bar"); | ||
} | ||
} | ||
}; | ||
var CLI = exports.CLI = { | ||
name: "menhera-cli", | ||
awake: function awake(_ref5) { | ||
var _ = _ref5._; | ||
_.CLI = { structs: {}, Event: new _events.EventEmitter() }; | ||
_.onCli = function (_ref6) { | ||
var name = _ref6.name, | ||
props = _ref6.props; | ||
var desc = props.desc, | ||
exec = props.exec; | ||
_.CLI.structs[name] = props; | ||
_.CLI.Event.on(name, exec); | ||
}; | ||
}, | ||
start: function start(_ref7) { | ||
var _ = _ref7._; | ||
var _process$argv$slice = process.argv.slice(2), | ||
_process$argv$slice2 = _toArray(_process$argv$slice), | ||
command = _process$argv$slice2[0], | ||
val = _process$argv$slice2.slice(1); | ||
_.CLI.Event.emit(command, { _: _, val: val }); | ||
}, | ||
onCli: { | ||
foo: { | ||
exec: function exec(_ref8) { | ||
var _ = _ref8._, | ||
val = _ref8.val; | ||
console.log("bar"); | ||
} | ||
} | ||
} | ||
}; |
{ | ||
"name": "menhera", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"main": "dist", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -12,3 +12,3 @@ # Menhera | ||
const menhera = new Menhera({ | ||
const _ = new Menhera({ | ||
components: [ | ||
@@ -22,13 +22,13 @@ Observer, | ||
}, | ||
start() { | ||
this.state.test1 = "test1"; | ||
this.state.test2 = "test2"; | ||
this.emit("test4", "test", "4"); | ||
this.emit("test5", "test", "5"); | ||
start({ _ }) { | ||
_.state.test1 = "test1"; | ||
_.state.test2 = "test2"; | ||
_.emit("test4", "test", "4"); | ||
_.emit("test5", "test", "5"); | ||
}, | ||
observer: { | ||
test1(val) { | ||
test1({ val }) { | ||
console.log(val); | ||
}, | ||
test2(val) { | ||
test2({ val }) { | ||
console.log(val); | ||
@@ -38,6 +38,6 @@ } | ||
on: { | ||
test4(...val) { | ||
test4({ val }) { | ||
console.log(val.join("")); | ||
}, | ||
test5(...val) { | ||
test5({ val }) { | ||
console.log(val.join("")); | ||
@@ -44,0 +44,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12108
261
0