Comparing version 0.0.1 to 0.0.2
@@ -11,2 +11,14 @@ 'use strict'; | ||
var _plugins = require('./plugins'); | ||
Object.keys(_plugins).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins[key]; | ||
} | ||
}); | ||
}); | ||
var _events = require('events'); | ||
@@ -16,6 +28,4 @@ | ||
var _plugins = require('./plugins'); | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -25,4 +35,3 @@ | ||
components: [_plugins.Observer, _plugins.Event], | ||
lifeCycle: ["awake", "start"], | ||
keywords: ["observer", "on"] | ||
lifeCycle: ["awake", "start"] | ||
}; | ||
@@ -34,3 +43,3 @@ | ||
this.struct = {}; | ||
this.structs = {}; | ||
this.config = (0, _utils.ConfigMerger)(initConfig, config); | ||
@@ -45,43 +54,28 @@ } | ||
var _config = this.config, | ||
components = _config.components, | ||
keywords = _config.keywords, | ||
_config$components = _config.components, | ||
components = _config$components === undefined ? [] : _config$components, | ||
lifeCycle = _config.lifeCycle; | ||
var _lifeCycle = _toArray(lifeCycle), | ||
awake = _lifeCycle[0], | ||
lifeCycles = _lifeCycle.slice(1); | ||
if (components) { | ||
components.forEach(function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(comp) { | ||
var struct, name; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
struct = (0, _utils.typeParser)({ | ||
obj: comp | ||
}); | ||
name = struct.props.name; | ||
components.forEach(function (comp) { | ||
var struct = (0, _utils.typeParser)({ | ||
obj: comp | ||
}); | ||
var name = struct.props.name, | ||
events = struct.events; | ||
_this.struct[name] = struct; | ||
_this.structs[name] = struct; | ||
events[awake] && events[awake].call(_this); | ||
}); | ||
case 3: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
})); | ||
Object.values(this.structs).forEach(function (struct) { | ||
var props = struct.props, | ||
events = struct.events; | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
Object.values(this.struct).forEach(function (struct) { | ||
var events = struct.events, | ||
name = struct.events.name, | ||
props = struct.props; | ||
keywords.forEach(function (keyword) { | ||
if (props[keyword]) { | ||
Object.keys(props).forEach(function (prop) { | ||
if (typeof _this[prop] === 'function') { | ||
var _iteratorNormalCompletion = true; | ||
@@ -92,13 +86,11 @@ var _didIteratorError = false; | ||
try { | ||
for (var _iterator = Object.entries(props[keyword])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref2 = _step.value; | ||
for (var _iterator = Object.entries(props[prop])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref = _step.value; | ||
var _ref3 = _slicedToArray(_ref2, 2); | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var key = _ref3[0]; | ||
var value = _ref3[1]; | ||
var key = _ref2[0]; | ||
var value = _ref2[1]; | ||
if (typeof _this[keyword] == "function") { | ||
_this[keyword].call(_this, key, value); | ||
} | ||
_this[prop].call(_this, key, value); | ||
} | ||
@@ -122,3 +114,3 @@ } catch (err) { | ||
lifeCycle.forEach(function (key) { | ||
lifeCycles.forEach(function (key) { | ||
events[key] && events[key].call(_this); | ||
@@ -125,0 +117,0 @@ }); |
@@ -13,2 +13,3 @@ "use strict"; | ||
awake: function awake() { | ||
this.Observer = new _events.EventEmitter(); | ||
@@ -15,0 +16,0 @@ this.state = {}; |
@@ -17,18 +17,18 @@ "use strict"; | ||
var obj = _ref.obj, | ||
_ref$struct = _ref.struct, | ||
struct = _ref$struct === undefined ? {} : _ref$struct, | ||
other = _objectWithoutProperties(_ref, ["obj", "struct"]); | ||
_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 (!struct[key]) { | ||
struct[key] = {}; | ||
if (!structs[key]) { | ||
structs[key] = {}; | ||
} | ||
other[key].forEach(function (keyword) { | ||
struct[key][keyword] = obj[keyword]; | ||
structs[key][keyword] = obj[keyword]; | ||
}); | ||
} | ||
}); | ||
return struct; | ||
return structs; | ||
}; | ||
@@ -40,14 +40,14 @@ | ||
obj = _ref2.obj, | ||
_ref2$struct = _ref2.struct, | ||
struct = _ref2$struct === undefined ? {} : _ref2$struct; | ||
_ref2$structs = _ref2.structs, | ||
structs = _ref2$structs === undefined ? {} : _ref2$structs; | ||
struct = _extends({}, struct, { props: {}, events: {} }); | ||
structs = _extends({}, structs, { props: {}, events: {} }); | ||
Object.keys(obj).forEach(function (key) { | ||
if (typeof obj[key] === 'function') { | ||
struct["events"][key] = obj[key]; | ||
structs["events"][key] = obj[key]; | ||
} else { | ||
struct["props"][key] = obj[key]; | ||
structs["props"][key] = obj[key]; | ||
} | ||
}); | ||
return struct; | ||
return structs; | ||
}; | ||
@@ -54,0 +54,0 @@ |
@@ -5,5 +5,3 @@ import Menhera, {Observer, Event} from "../src" | ||
const menhera = new Menhera({ | ||
keywords:["test"], | ||
plugins:[Observer, Event], | ||
components: [{ | ||
components: [Observer, Event, { | ||
name: "test", | ||
@@ -14,2 +12,3 @@ awake(){ | ||
start(){ | ||
console.log("12321") | ||
this.state.test1 = "test1" | ||
@@ -16,0 +15,0 @@ this.state.test2 = "test2" |
{ | ||
"name": "menhera", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "lib", | ||
@@ -13,6 +13,6 @@ "scripts": { | ||
"babel-preset-env": "^1.6.1", | ||
"nodemon": "^1.11.0", | ||
"babel-preset-stage-3": "^6.24.1" | ||
"babel-preset-stage-3": "^6.24.1", | ||
"nodemon": "^1.11.0" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -1,2 +0,2 @@ | ||
#Menhera | ||
# Menhera | ||
an experimental lovely frame | ||
@@ -11,7 +11,4 @@ | ||
const menhera = new Menhera({ | ||
keywords:["test"], | ||
plugins:[Observer, Event], | ||
components: [{ | ||
components: [Observer, Event, { | ||
name: "test", | ||
@@ -18,0 +15,0 @@ awake(){ |
@@ -9,8 +9,10 @@ import { | ||
} from './utils' | ||
import {Observer, Event} from "./plugins" | ||
import { | ||
Observer, | ||
Event | ||
} from "./plugins" | ||
const initConfig = { | ||
components: [Observer, Event], | ||
lifeCycle: ["awake", "start"], | ||
keywords: ["observer", "on"], | ||
lifeCycle: ["awake", "start"] | ||
} | ||
@@ -21,3 +23,3 @@ export * from "./plugins" | ||
constructor(config) { | ||
this.struct = {} | ||
this.structs = {} | ||
this.config = ConfigMerger(initConfig, config) | ||
@@ -27,35 +29,31 @@ } | ||
const { | ||
components, | ||
keywords, | ||
lifeCycle | ||
components = [], | ||
lifeCycle | ||
} = this.config | ||
const [awake, ...lifeCycles] = lifeCycle | ||
if (components) { | ||
components.forEach(async comp => { | ||
let struct = typeParser({ | ||
obj: comp, | ||
}) | ||
const { | ||
props: { | ||
name | ||
} | ||
} = struct | ||
this.struct[name] = struct | ||
components.forEach(comp => { | ||
let struct = typeParser({ | ||
obj: comp, | ||
}) | ||
} | ||
const { | ||
props: { | ||
name, | ||
}, | ||
events | ||
} = struct | ||
this.structs[name] = struct | ||
events[awake] && events[awake].call(this) | ||
}) | ||
Object.values(this.struct).forEach(struct => { | ||
Object.values(this.structs).forEach(struct => { | ||
const { | ||
events, | ||
events: { | ||
name | ||
}, | ||
props, | ||
events | ||
} = struct | ||
keywords.forEach(keyword => { | ||
if (props[keyword]) { | ||
for (const [key, value] of Object.entries(props[keyword])) { | ||
if (typeof this[keyword] == "function") { | ||
this[keyword].call(this, key, value) | ||
} | ||
Object.keys(props).forEach(prop => { | ||
if (typeof this[prop] === 'function') { | ||
for (const [key, value] of Object.entries(props[prop])) { | ||
this[prop].call(this, key, value) | ||
} | ||
@@ -65,3 +63,3 @@ } | ||
lifeCycle.forEach(key => { | ||
lifeCycles.forEach(key => { | ||
events[key] && events[key].call(this) | ||
@@ -68,0 +66,0 @@ }) |
@@ -8,2 +8,3 @@ import { | ||
awake() { | ||
this.Observer = new EventEmitter | ||
@@ -10,0 +11,0 @@ this.state = {} |
export const keyParser = ({ | ||
obj, | ||
struct = {}, | ||
structs = {}, | ||
...other | ||
@@ -8,27 +8,28 @@ }= {}) => { | ||
if (Array.isArray(other[key])) { | ||
if (!struct[key]) { | ||
struct[key] = {} | ||
if (!structs[key]) { | ||
structs[key] = {} | ||
} | ||
other[key].forEach(keyword => { | ||
struct[key][keyword] = obj[keyword] | ||
structs[key][keyword] = obj[keyword] | ||
}) | ||
} | ||
}) | ||
return struct | ||
return structs | ||
} | ||
export const typeParser = ({ | ||
obj, | ||
struct = {}, | ||
structs = {}, | ||
} = {}) => { | ||
struct = {...struct, props:{}, events:{}} | ||
structs = {...structs, props:{}, events:{}} | ||
Object.keys(obj).forEach(key => { | ||
if (typeof obj[key] === 'function') { | ||
struct["events"][key] = obj[key] | ||
structs["events"][key] = obj[key] | ||
} else { | ||
struct["props"][key] = obj[key] | ||
structs["props"][key] = obj[key] | ||
} | ||
}) | ||
return struct | ||
return structs | ||
} | ||
@@ -35,0 +36,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
170993
5061
41
1