mirror of
https://github.com/lucaspalomodevelop/varkeeper.git
synced 2026-03-12 23:37:21 +00:00
add prop class
This commit is contained in:
parent
2b5748515c
commit
7b28002932
38
src/index.js
38
src/index.js
@ -1,6 +1,40 @@
|
||||
let props = [];
|
||||
let events = [];
|
||||
|
||||
// Prop = function(name, value = undefined) {
|
||||
// this._init(name, value);
|
||||
// // props.push({ name: name, value: value });
|
||||
// }
|
||||
// Prop.prototype = {
|
||||
|
||||
// constructor: Prop,
|
||||
// name: null,
|
||||
// value: null,
|
||||
// _init: function(name, value = undefined) {
|
||||
|
||||
// if(value === undefined && props.find(x => x.name === name) !== undefined)
|
||||
// {
|
||||
// myprop = props.find(x => x.name === name);
|
||||
// console.log(myprop)
|
||||
// setprop(name, myprop.value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// setprop(name, value);
|
||||
// }
|
||||
// //
|
||||
// // this.value = value;
|
||||
|
||||
// },
|
||||
// set: function (value) {setprop(this.name, value);},
|
||||
// get: function () {return getprop(this.name);},
|
||||
// delete: function () {deleteprop(this.name);},
|
||||
// on: function(eventname, callback) {
|
||||
// events.push({ type: eventname, callback: callback, name: this.name });
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
function setprop(name, value) {
|
||||
|
||||
if (value instanceof Function) {
|
||||
@ -17,7 +51,8 @@ function setprop(name, value) {
|
||||
}
|
||||
else
|
||||
{
|
||||
props.push( {name: name, value: value});
|
||||
// props.push(new Prop(name, value));
|
||||
props.push({ name: name, value: value });
|
||||
}
|
||||
|
||||
onchange_func(name, value);
|
||||
@ -33,6 +68,7 @@ function getEventsFromTypeAndName(name,type) {
|
||||
}
|
||||
|
||||
function getprop(name) {
|
||||
console.log(props)
|
||||
let result = props.find(x => x.name === name)
|
||||
if(result != undefined)
|
||||
{
|
||||
|
||||
26
test/test.js
26
test/test.js
@ -6,11 +6,14 @@ const assertArrays = require('chai-arrays');
|
||||
chai.use(assertArrays);
|
||||
let varkeeper = require("../src/index.js");
|
||||
|
||||
|
||||
|
||||
describe('varkeeper', () => {
|
||||
describe('setprop', () => {
|
||||
it('will set a prop', () => {
|
||||
varkeeper.setprop('test', 'value');
|
||||
assert.equal(varkeeper.getprop('test'), 'value');
|
||||
varkeeper.setprop('test', 'value');
|
||||
//let a = new varkeeper.Prop('test')
|
||||
assert.equal(varkeeper.getprop("test"), 'value');
|
||||
});
|
||||
it('will set a prop as array', () => {
|
||||
varkeeper.setprop('array', []);
|
||||
@ -56,4 +59,23 @@ describe('varkeeper', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('varkeeper porp class', () => {
|
||||
it("", () => {
|
||||
console.log("varkeeper")
|
||||
varkeeper.setprop("array","blub")
|
||||
varkeeper.getprop("array");
|
||||
console.log("prop class")
|
||||
var a = new varkeeper.Prop("array",undefined)
|
||||
a.get();
|
||||
a.on("onchange",()=>{
|
||||
console.log("onchange")
|
||||
})
|
||||
console.log("first",a.get());
|
||||
a.set("B")
|
||||
console.log(a.get());
|
||||
varkeeper.setprop("array","C")
|
||||
console.log(a.get());
|
||||
})
|
||||
})
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user