1.5.4 • Published 9 years ago

store-api-wrapper v1.5.4

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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: "johndoe@example.com"});

Sub Stores

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

Special Listerners

  users.onIsEqualTo({email: "billdoe@example.com"}, function(){
    console.log("Is now Bill Doe's email")
  });

  users.set({email: "billdoe@example.com"})

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)
  })
1.5.4

9 years ago

1.5.3

9 years ago

1.5.1

9 years ago

1.5.0

9 years ago

1.4.0

10 years ago

1.3.9

10 years ago

1.3.8

10 years ago

1.3.7

10 years ago

1.3.6

10 years ago

1.3.5

10 years ago

1.3.4

10 years ago

1.3.3

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.9

10 years ago

1.2.8

10 years ago

1.2.7

10 years ago

1.2.6

10 years ago

1.2.5

10 years ago

1.2.4

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.9

10 years ago

1.1.8

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago