Comparing version 0.0.3 to 0.0.4
@@ -1,34 +0,36 @@ | ||
import Menhera, {Observer, Event} from "../src" | ||
import Menhera, { Observer, Event } from "../src"; | ||
const menhera = new Menhera({ | ||
components: [Observer, Event, { | ||
name: "test", | ||
awake(){ | ||
console.log("test0") | ||
}, | ||
start(){ | ||
console.log("12321") | ||
this.state.test1 = "test1" | ||
this.state.test2 = "test2" | ||
this.emit("test4","test","4") | ||
this.emit("test5", "test","5") | ||
}, | ||
observer:{ | ||
test1(val){ | ||
console.log(val) | ||
components: [ | ||
Observer, | ||
Event, | ||
{ | ||
name: "test", | ||
awake() { | ||
console.log("test0"); | ||
}, | ||
test2(val){ | ||
console.log(val) | ||
} | ||
}, | ||
on:{ | ||
test4(...val){ | ||
console.log(val.join("")) | ||
start() { | ||
this.state.test1 = "test1"; | ||
this.state.test2 = "test2"; | ||
this.emit("test4", "test", "4"); | ||
this.emit("test5", "test", "5"); | ||
}, | ||
test5(...val){ | ||
console.log(val.join("")) | ||
observer: { | ||
test1(val) { | ||
console.log(val); | ||
}, | ||
test2(val) { | ||
console.log(val); | ||
} | ||
}, | ||
on: { | ||
test4(...val) { | ||
console.log(val.join("")); | ||
}, | ||
test5(...val) { | ||
console.log(val.join("")); | ||
} | ||
} | ||
} | ||
}] | ||
}).init() | ||
] | ||
}).init(); |
export const TestPlugin = { | ||
name: "test", | ||
awake(){ | ||
} | ||
} | ||
name: "test", | ||
awake() {} | ||
}; |
{ | ||
"name": "menhera", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "lib", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# Menhera | ||
an experimental lovely frame | ||
@@ -9,34 +10,38 @@ | ||
```js | ||
import Menhera, {Observer, Event} from "menhera" | ||
import Menhera, { Observer, Event } from "menhera"; | ||
const menhera = new Menhera({ | ||
components: [Observer, Event, { | ||
name: "test", | ||
awake(){ | ||
console.log("test0") | ||
}, | ||
start(){ | ||
this.state.test1 = "test1" | ||
this.state.test2 = "test2" | ||
this.emit("test4","test","4") | ||
this.emit("test5", "test","5") | ||
}, | ||
observer:{ | ||
test1(val){ | ||
console.log(val) | ||
components: [ | ||
Observer, | ||
Event, | ||
{ | ||
name: "test", | ||
awake() { | ||
console.log("test0"); | ||
}, | ||
test2(val){ | ||
console.log(val) | ||
} | ||
}, | ||
on:{ | ||
test4(...val){ | ||
console.log(val.join("")) | ||
start() { | ||
this.state.test1 = "test1"; | ||
this.state.test2 = "test2"; | ||
this.emit("test4", "test", "4"); | ||
this.emit("test5", "test", "5"); | ||
}, | ||
test5(...val){ | ||
console.log(val.join("")) | ||
observer: { | ||
test1(val) { | ||
console.log(val); | ||
}, | ||
test2(val) { | ||
console.log(val); | ||
} | ||
}, | ||
on: { | ||
test4(...val) { | ||
console.log(val.join("")); | ||
}, | ||
test5(...val) { | ||
console.log(val.join("")); | ||
} | ||
} | ||
} | ||
}] | ||
}).init() | ||
``` | ||
] | ||
}).init(); | ||
``` |
@@ -1,13 +0,4 @@ | ||
import { | ||
EventEmitter | ||
} from 'events' | ||
import { | ||
keyParser, | ||
typeParser, | ||
ConfigMerger | ||
} from './utils' | ||
import { | ||
Observer, | ||
Event | ||
} from "./plugins" | ||
import { EventEmitter } from "events"; | ||
import { keyParser, typeParser, ConfigMerger } from "./utils"; | ||
import { Observer, Event } from "./plugins"; | ||
@@ -17,50 +8,39 @@ const initConfig = { | ||
lifeCycle: ["awake", "start"] | ||
} | ||
export * from "./plugins" | ||
}; | ||
export * from "./plugins"; | ||
export default class Menhera { | ||
constructor(config) { | ||
this.structs = {} | ||
this.config = ConfigMerger(initConfig, config) | ||
this.structs = {}; | ||
this.config = ConfigMerger(initConfig, config); | ||
} | ||
init() { | ||
const { | ||
components = [], | ||
lifeCycle | ||
} = this.config | ||
const [awake, ...lifeCycles] = lifeCycle | ||
const { components = [], lifeCycle } = this.config; | ||
const [awake, ...lifeCycles] = lifeCycle; | ||
components.forEach(comp => { | ||
let struct = typeParser({ | ||
obj: comp, | ||
}) | ||
const { | ||
props: { | ||
name, | ||
}, | ||
events | ||
} = struct | ||
this.structs[name] = struct | ||
events[awake] && events[awake].call(this) | ||
}) | ||
obj: comp | ||
}); | ||
const { props: { name }, events } = struct; | ||
this.structs[name] = struct; | ||
events[awake] && events[awake].call(this); | ||
}); | ||
Object.values(this.structs).forEach(struct => { | ||
const { | ||
props, | ||
events | ||
} = struct | ||
const { props, events } = struct; | ||
Object.keys(props).forEach(prop => { | ||
if (typeof this[prop] === 'function') { | ||
if (typeof this[prop] === "function") { | ||
for (const [key, value] of Object.entries(props[prop])) { | ||
this[prop].call(this, key, value) | ||
this[prop].call(this, key, value); | ||
} | ||
} | ||
}) | ||
}); | ||
lifeCycles.forEach(key => { | ||
events[key] && events[key].call(this) | ||
}) | ||
}) | ||
events[key] && events[key].call(this); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
@@ -1,49 +0,45 @@ | ||
import { | ||
EventEmitter | ||
} from 'events' | ||
import { EventEmitter } from "events"; | ||
export const Observer = { | ||
name: "observer", | ||
awake() { | ||
this.Observer = new EventEmitter | ||
this.state = {} | ||
this._state = {} | ||
let _this = this | ||
this.state = new Proxy(this._state, { | ||
get(target, key) { | ||
if (key in target) { | ||
return target[key] | ||
} else { | ||
target[key] = null; | ||
return null | ||
} | ||
}, | ||
set(target, key, val) { | ||
target[key] = val | ||
_this.Observer.emit(key, val) | ||
return true | ||
} | ||
}) | ||
this.observer = (name, fn) => { | ||
_this.Observer.on(name, fn) | ||
name: "observer", | ||
awake() { | ||
this.Observer = new EventEmitter(); | ||
this.state = {}; | ||
this._state = {}; | ||
let _this = this; | ||
this.state = new Proxy(this._state, { | ||
get(target, key) { | ||
if (key in target) { | ||
return target[key]; | ||
} else { | ||
target[key] = null; | ||
return null; | ||
} | ||
}, | ||
}, | ||
set(target, key, val) { | ||
target[key] = val; | ||
_this.Observer.emit(key, val); | ||
return true; | ||
} | ||
}); | ||
this.observer = (name, fn) => { | ||
_this.Observer.on(name, fn); | ||
}; | ||
} | ||
}; | ||
} | ||
export const Event = { | ||
name: "event", | ||
awake() { | ||
this.Event = new EventEmitter | ||
this.on = (name, fn) => { | ||
this.Event.on(name, fn) | ||
return this | ||
} | ||
name: "event", | ||
awake() { | ||
this.Event = new EventEmitter(); | ||
this.on = (name, fn) => { | ||
this.Event.on(name, fn); | ||
return this; | ||
}; | ||
this.emit = (name, ...args) => { | ||
this.Event.emit(name, ...args) | ||
return this | ||
} | ||
} | ||
} | ||
this.emit = (name, ...args) => { | ||
this.Event.emit(name, ...args); | ||
return this; | ||
}; | ||
} | ||
}; |
@@ -1,42 +0,34 @@ | ||
export const keyParser = ({ | ||
obj, | ||
structs = {}, | ||
...other | ||
}= {}) => { | ||
export const keyParser = ({ obj, structs = {}, ...other } = {}) => { | ||
Object.keys(other).forEach(key => { | ||
if (Array.isArray(other[key])) { | ||
if (!structs[key]) { | ||
structs[key] = {} | ||
structs[key] = {}; | ||
} | ||
other[key].forEach(keyword => { | ||
structs[key][keyword] = obj[keyword] | ||
}) | ||
structs[key][keyword] = obj[keyword]; | ||
}); | ||
} | ||
}) | ||
return structs | ||
} | ||
}); | ||
return structs; | ||
}; | ||
export const typeParser = ({ | ||
obj, | ||
structs = {}, | ||
} = {}) => { | ||
structs = {...structs, props:{}, events:{}} | ||
export const typeParser = ({ obj, structs = {} } = {}) => { | ||
structs = { ...structs, props: {}, events: {} }; | ||
Object.keys(obj).forEach(key => { | ||
if (typeof obj[key] === 'function') { | ||
structs["events"][key] = obj[key] | ||
if (typeof obj[key] === "function") { | ||
structs["events"][key] = obj[key]; | ||
} else { | ||
structs["props"][key] = obj[key] | ||
structs["props"][key] = obj[key]; | ||
} | ||
}) | ||
return structs | ||
} | ||
}); | ||
return structs; | ||
}; | ||
export const ConfigMerger = (Obj1, Obj2) => { | ||
let cache = Obj1 | ||
let cache = Obj1; | ||
Object.keys(Obj2).forEach(key => { | ||
cache[key] = [...Obj1[key] || [], ...Obj2[key]] | ||
}) | ||
return cache | ||
} | ||
cache[key] = [...(Obj1[key] || []), ...Obj2[key]]; | ||
}); | ||
return cache; | ||
}; |
Sorry, the diff of this file is not supported yet
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
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
167649
4848
47
9