0.1.3 • Published 7 years ago

mobx-rest-store v0.1.3

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

Build Status

mobx-rest-store

A mobx based collection and model inspired by backbonejs, and @mobx-rest

Installation

npm

npm install --save mobx-rest-store mobx

yarn

yarn add mobx-rest-store

Usage

import { Collection, BaseModel, AxiosTransportApi } from 'mobx-rest-store'

class StoreModel extends BaseModel {
  getFields() {
    return ['_id', 'name', 'createdAt', 'updatedAt']
  }
}

class MyAPITransporter extends AxiosTransportApi{
  baseUrl='http://my.api.com'
}

let personApi = new class TransportMockApi extends MyAPITransporter {
  constructor() {
    super('/Persons')
  }
}

let stores = new class Stores extends Collection {
  model = StoreModel
  constructor() {
    super()
    this.api = personApi
  }
}


// Create new Person Model
const model = stores.build({name: 'Juan'})

// make changes
model.set('name', 'Peter')
model.save().then(()=>{
  console.log('saved')
}).catch(e=>{
  console.error(e)
})

// remove
model.remove().then(()=>{
  console.log('removed')
}).catch(e=>{
  console.error(e)
})
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2-rc4

7 years ago

0.0.2-rc3

7 years ago

0.0.2-rc2

7 years ago

0.0.2-rc1

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago