mirror of
https://github.com/lucaspalomodevelop/varkeeper.git
synced 2026-03-12 23:37:21 +00:00
add ifis funtion | resturcture code | added ifis test
This commit is contained in:
parent
4dc7aa0a38
commit
e2c940b9f3
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "varkeeper",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"devDependencies": {
|
||||
|
||||
46
src/index.js
46
src/index.js
@ -8,15 +8,20 @@ function setprop(name, value) {
|
||||
}
|
||||
|
||||
props[name] = value;
|
||||
if (events.length > 0) {
|
||||
let onchangeevents = events.filter(x => x.name === name && x.type === 'onchange')
|
||||
|
||||
onchangeevents.forEach(element => {
|
||||
element.callback(value);
|
||||
});
|
||||
}
|
||||
onchange_func(name, value);
|
||||
ifis_func(name, value)
|
||||
|
||||
}
|
||||
|
||||
function getEventsFromTypeAndName(name,type) {
|
||||
let event = [];
|
||||
if (events.length > 0) {
|
||||
event = events.filter(x => x.name === name && x.type === type)
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
function getprop(name) {
|
||||
return props[name];
|
||||
}
|
||||
@ -25,14 +30,29 @@ function onchange(name, callback) {
|
||||
events.push({ name: name, callback: callback, type: 'onchange' });
|
||||
}
|
||||
|
||||
function ifistrue(name, condition , callback) {
|
||||
|
||||
if(condition) {
|
||||
callback();
|
||||
function onchange_func(name,value){
|
||||
if (events.length > 0) {
|
||||
let onchangeevents = getEventsFromTypeAndName(name, 'onchange');
|
||||
|
||||
onchangeevents.forEach(element => {
|
||||
element.callback(value);
|
||||
});
|
||||
}
|
||||
events.push({ name: name, callback: callback, type: 'ifistrue' });
|
||||
}
|
||||
|
||||
function ifis(name, condition , callback) {
|
||||
events.push({ name: name, callback: callback, condition: condition, type: 'ifis' });
|
||||
}
|
||||
function ifis_func(name, value) {
|
||||
let ifisevent = getEventsFromTypeAndName(name, 'ifis');
|
||||
ifisevent.forEach(element => {
|
||||
if(element.condition){
|
||||
element.callback(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = { setprop, getprop, onchange }
|
||||
|
||||
module.exports = { setprop, getprop, onchange, ifis }
|
||||
@ -47,4 +47,13 @@ describe('varkeeper', () => {
|
||||
assert.equal(a, true);
|
||||
});
|
||||
});
|
||||
describe('ifis', () => {
|
||||
it('will call funtion by change prop value', (done) => {
|
||||
varkeeper.ifis('test', varkeeper.getprop('test').length > 1 , (value) => {
|
||||
done();
|
||||
});
|
||||
varkeeper.setprop('test', [1,2,3]);
|
||||
throw new Error();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user