modl-js
v0.4.0
Published
A mutation base model management library, inspired by the Flux pattern
Downloads
2
Readme
Modl
A mutation base model management library, inspired by the Flux pattern.
Install
# yarn
yarn add modl-js
# npm
npm install modl-js
Usage
import Modl from 'modl-js';
Modl.use(Modl.middlewares.type)
.use(Modl.middlewares.default);
const Person = Modl({
fields: {
fisrtName: {
type: String
},
lastName: {
type: String
},
birthDate: {
type: Date,
default() {
return new Date();
}
}
},
computed: {
age(store) {
const ageDif = new Date(Date.now() - store.birthDate.getTime());
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
}
});
const me = new Person({
firstName: 'mod',
lastName: 'elo',
birthDate: new Date('2017-10-15T15:45:48Z')
});
Mutating
import Modl from 'modl-js';
const Person = Modl({
fields: {
fisrtName: {
type: String
}
},
mutations: {
CHANGE_NAME(store, name) {
store.name = name;
}
}
});
const me = new Person({
firstName: 'modl'
});
me.mutated(() => { console.info('changed'); });
me.commit('CHANGE_NAME', 'bob');
Actions
import Modl from 'modl-js';
const Person = Modl({
fields: {
fisrtName: {
type: String
}
},
mutations: {
CHANGE_NAME(store, name) {
store.name = name;
}
},
actions: {
setName(store, name) {
return new Promise((resolve) => {
setTimeout(() => {
store.commit('CHANGE_NAME', name);
resolve();
}, 3000);
});
}
}
});
const me = new Person({
firstName: 'modl'
});
me.mutated(() => { console.info('changed'); });
me.setName('bob').then(() => {
console.info('done');
});
Run tests
npm run test
Build
npm run build
Requirement
Object.assign
Array.concat
WeakMap
Set
Road map
- [x] Properties management
- [x] Actions and mutations management
- [x] Properties extansibility
- [x] Inheritance
- [x] Flat inheritance
- [] Behavior management
- [] Documentation