js-reactive-model

0.1.0 • Public • Published

js-model is a library to create watchable objects/models using Proxy and Reflect, written in pure javascript with no dependency. Api is simliar to vuex with support for:

  • Watch for array operations

  • Deep watch

  • Mutations and actions

import jsmodel from 'js-model'


        let def = {
            state() {
                return {
                    name: 'Jay',
                    mobile: '123456789',
                    skills: ['java', 'react', 'vue', 'architecture'],
                    company: {
                        name: 'Essue',
                        position: 'Founder'
                    }
                }
            },
            mutations: {

            },
            actions: {

            }
        }
        let model = jsmodel(def);

        model.watch('name', (oldVal, newVal) => {
            console.log('name changed')
        });
        model.watch('skills', (oldVal, newVal) => {
            console.log('skills changed')
        });

        model.watch('company', () => {
            console.log('company changed');
        }, {
            deep: true
        });


        model.name = 'Kevin'
        model.skills.push('Distributed Systems');
        model.skills = [];
        model.company.name = 'Coolzhua Tech'
        
         

Readme

Keywords

none

Package Sidebar

Install

npm i js-reactive-model

Weekly Downloads

0

Version

0.1.0

License

ISC

Unpacked Size

10.9 kB

Total Files

8

Last publish

Collaborators

  • javcly