Git Product home page Git Product logo

air-store's Introduction

modular state store for component communication

Reference

  • Step 0. Import Air in Your Code

var Air = require('air-store')
import Air from 'air-store'
  • Step 1. Create and Initialize a Module

    Air(name: string, initVals: object): function

var airUser = Air('user', {
  data: {
    name: 'venecy',
    id: 001,
    mail: '[email protected]'
  },
  computed: {
    info: function (store) {
      return {
        name: store.name,
        id: store.id,
        mail: store.mail
      }
    }
  },
  watcher: {
    name: function (val, oldVal) {
      console.log('>>> new name is: ', val)
    }
  }
})
  • As you can see, the initVals param has three part:

    data - for the values store in the module;

    computed - for computed values;

    watcher - for wath property value changes, execute when property is set new value;

    You can only modify properties you initialzed. Once you initialize a module, you can not add properties to it anymore.

  • Step 2. Access Values Store in Module

airUser.name // 'venecy'
airUser.id // 001
airUser.info // {name: "venecy", id: 001, mail: "[email protected]"}
  • Step 3. Update Values Store in Module

airUser({name: 'vinice'}) // '>>> new name is: vinice' (watcher is execute)
airUser.name // vinice
airUser.info // {name: "vinice", id: 001, mail: "[email protected]"}
  • Setp 4. Actions

airUser({info: ''}, function() {
  // do some you want ... 
  airUser({
    name: 'vince_0',
    id: 002,
    mail: '[email protected]'
  })
})

air-store's People

Contributors

gulewei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.