saga-model
v0.0.2
Published
ActiveRecord like Stamp via Redux Saga Rest
Downloads
1
Readme
saga-model
ActiveRecord like stamp via Redux Saga Rest
Configuration
npm install saga-model
API
- stampCreator(baseUrl): create stamp with input baseUrl
- static:
- idAttribute: 'id' (default)
- baseUrl: specified baseUrl for restful api
- api: saga rest api with pre-defined middleware auth and json
- url(path = '.'): function to return url for specified relative path
- fetchOne(id): restful get instance with specified id
- fetchAll(data = null): restful get list of instance with specified data
- method:
- getStamp(): return stamp of this object
- isNew(): return if object a new object without id
- parse(data = {}): return post prcoessed data of http response data
- fetch(): load single record from rest server
- save(values = {}): save records combined with input values into rest server
- destroy(): destroy this instance on the rest server
- middleware:
- json: parse response body stream and save result into res.data, also throw error if not res.ok
- auth: acquire oauth2 token till login resolved or rejected
Create customized stamp on top of ActiveRecord like Stamp
- stampCreator = require 'saga-model'
- create default stamp with specified url (e.g. #{location.href}/api/user)
- compose stamp with extended staic or instance methods
stampCreator = require 'saga-model'
User = stampCreator "#{location.href}/api/user"
Admin = User
.methods
isAdmin: ->
return true
Webpack loader (webpack.config.coffee)
babelLoader =
loader: 'babel-loader'
query:
plugins: [
[
'transform-runtime'
{
helpers: false
polyfill: true
regenerator: true
moduleName: 'babel-runtime'
}
]
]
presets: [
'es2015'
'stage-2'
]
module.exports =
entry: ...
output: ...
plugins: ...
module:
loaders: [
{
test: /saga\-model/
use: [ babelLoader ]
}
...
]