Git Product home page Git Product logo

store-api-wrapper's Introduction

Store Api Wrapper (Model)

Models

  User = Model({
    api: Client("/api/users"),
    store: Store("users")
  })

Stores

Store Instance

  users = Store("users");

Get

  users.get()

Listen for changes

  users.onChange(function(){
    console.log(users.get())
  })

Set

  users.set({email: "[email protected]"});

Sub Stores

  userId = 1
  users.store(userId).store("profiles").set([{
    firstName: "John",
    lastName: "Doe"
  }]);

Special Listerners

  users.onIsEqualTo({email: "[email protected]"}, function(){
    console.log("Is now Bill Doe's email")
  });

  users.set({email: "[email protected]"})

All Other Listeners

update
change
empty
blank
create
notBlank
isObject
isArray
isString
isNumber
increase
decrease

Store Mixin

      React.createClass({
        mixins: [Store.ReactMixin],
        followStores: function() {
          // Can be an array, object, or function that returns an array or object
          // Arrays can contain strings or objects
          // Strings will be both the state key and store key
          // Object keys will be the state key and values will be the store key
          // return ["users", { organization: "currentOrganization"]
          return {
            users: "users",
            assessments: "assessments"
          }
        },
        componentDidMount: function() {
          this.followChange(Store("users.params").onChange(function() {
            // Follow more changes
          }))
        }
      })
      // All the stores or changes that are followed, will be detached in componentDidUnmount

Client

  ApiClient = {
    users: Client("/api/users"),
    organizations: Client({"/api/organizations", scope: "find"})
  }
  ApiClient.users.findOne({id: 10}).then(function(user){
    console.log(user)
  })

store-api-wrapper's People

Contributors

carsonwright avatar tomprats avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  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.