Comparing version 0.1.1 to 0.1.2
@@ -6,8 +6,6 @@ "use strict"; | ||
}); | ||
exports.CLI = exports.Event = exports.Observer = undefined; | ||
exports.Event = exports.Observer = undefined; | ||
var _events = require("events"); | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
var Observer = exports.Observer = function Observer(_) { | ||
@@ -17,6 +15,7 @@ return { | ||
awake: function awake() { | ||
var _$config$observable = _.config.observable, | ||
observable = _$config$observable === undefined ? {} : _$config$observable; | ||
_.Observer = { Event: new _events.EventEmitter() }; | ||
_.state = {}; | ||
_._state = {}; | ||
_.state = new Proxy(_._state, { | ||
_.config.observable = new Proxy(observable, { | ||
get: function get(target, key) { | ||
@@ -79,38 +78,2 @@ if (key in target) { | ||
}; | ||
}; | ||
var CLI = exports.CLI = function CLI(_) { | ||
return { | ||
name: "menhera-cli", | ||
awake: function awake() { | ||
_.CLI = { structs: {}, Event: new _events.EventEmitter() }; | ||
_.onCli = function (_ref3) { | ||
var name = _ref3.name, | ||
props = _ref3.props; | ||
var desc = props.desc, | ||
exec = props.exec; | ||
_.CLI.structs[name] = props; | ||
_.CLI.Event.on(name, exec); | ||
}; | ||
}, | ||
start: function start() { | ||
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(_ref4) { | ||
var val = _ref4.val; | ||
console.log("bar"); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
@@ -11,50 +11,14 @@ "use strict"; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
var keyParser = function keyParser() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var obj = _ref.obj, | ||
_ref$structs = _ref.structs, | ||
structs = _ref$structs === undefined ? {} : _ref$structs, | ||
other = _objectWithoutProperties(_ref, ["obj", "structs"]); | ||
Object.keys(other).forEach(function (key) { | ||
if (Array.isArray(other[key])) { | ||
if (!structs[key]) { | ||
structs[key] = {}; | ||
} | ||
other[key].forEach(function (keyword) { | ||
structs[key][keyword] = obj[keyword]; | ||
}); | ||
} | ||
}); | ||
return structs; | ||
}; | ||
exports.keyParser = keyParser; | ||
var typeParser = exports.typeParser = function typeParser() { | ||
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
obj = _ref2.obj, | ||
_ref2$structs = _ref2.structs, | ||
structs = _ref2$structs === undefined ? {} : _ref2$structs; | ||
structs = _extends({}, structs, { props: {}, events: {} }); | ||
Object.keys(obj).forEach(function (key) { | ||
if (typeof obj[key] === "function") { | ||
structs["events"][key] = obj[key]; | ||
} else { | ||
structs["props"][key] = obj[key]; | ||
} | ||
}); | ||
return structs; | ||
}; | ||
var ConfigMerger = exports.ConfigMerger = function ConfigMerger(Obj1, Obj2) { | ||
var cache = Obj1; | ||
Object.keys(Obj2).forEach(function (key) { | ||
cache[key] = Array.from(new Set([].concat(_toConsumableArray(Obj1[key] || []), _toConsumableArray(Obj2[key])))); | ||
if (Array.isArray(Obj2[key])) { | ||
cache[key] = Array.from(new Set([].concat(_toConsumableArray(Obj1[key] || []), _toConsumableArray(Obj2[key])))); | ||
} else if (typeof Obj2[key] === "obj") { | ||
cache[key] = _extends({}, Obj1[key], Obj2[key]); | ||
} else { | ||
cache[key] = Obj2[key]; | ||
} | ||
}); | ||
return cache; | ||
}; |
{ | ||
"name": "menhera", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "dist", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -11,3 +11,2 @@ # Menhera | ||
import Menhera, { Observer, Event } from "menhera"; | ||
let Test = _ => ({ | ||
@@ -19,4 +18,6 @@ name: "test", | ||
start() { | ||
_.state.test1 = "test1"; | ||
_.state.test2 = "test2"; | ||
const { config: { observable: ob } } = _; | ||
ob.test1 = "test1"; | ||
ob.test2 = "test2"; | ||
ob.test3 = ob.test3; | ||
_.emit("test4", "test", "4"); | ||
@@ -31,2 +32,5 @@ _.emit("test5", "test", "5"); | ||
console.log(val); | ||
}, | ||
test3({ val }) { | ||
console.log(val); | ||
} | ||
@@ -45,4 +49,5 @@ }, | ||
const _ = new Menhera({ | ||
components: [Observer, Event, Test] | ||
components: [Observer, Event, Test], | ||
observable: { test3: "test3" } | ||
}).init(); | ||
``` |
50
10357
201