1.0.29 • Published 5 years ago
redux-provider v1.0.29
redux-provider
Redux provider is an immutable store for api request responses built with redux and redux-sagas. Support for React and Angular is built-in.
Features
- React support
- Angular support
- Schema type serializations
- Immutable store
- API Tokenization
- Tokenization
- Model preloading
- Request preloading
- Reusuable redux type responses
- Request transformation
- Response transformation
- Request cancellation
- Paremeter serialization
- Currently supports all HTTP request types
- Authorization
- Custom adapaters
- Upload and Download progress statuses
- Status Validations
- WebSockets
- Proxies
Usage
Provider
import Provider from 'redux-provider'
import { MyComponent } from './my-component'
import { Type } from './type' // example Type after this example
// need to update with dynamic importing
export const MyModel = new Provider({
basePath: apiUrl,
path: paths.PROVIDER_PATH, // basePath/path
token: ACCESS_TOKEN,
type: Type,
})
const myPreloadFunction = (params, enhance) => {
const type = 'MY_REDUX_TYPE'
const { someParam } = params
MyModel.post(
{
component: MyComponent, // optional currently for React only
type: type, // required
},
{
params: {
someParam: someParam,
type: type,
/*
"type" param is not required,
but good practice for backend developers to connect what is going on frontend wise.
*/
},
transformResponse: enhance,
/*
not required, but extra filter on response other than type property filters
*/
},
)
}
// Optional preload function for multiple request types
export const preloadMyModel = (params, enhance) => {
myPreloadFunction(params, enhance)
}
Provider Type
// Required response property types
const MyModel = {
name: String,
status: String,
user: String,
account: String,
created_at: String,
updated_at: String,
guid: String,
}
// Optional response property types
const MyModelOptions = {
rank: Number,
count: Number,
}
export const Type = {
defaults: MyModel,
options: MyModelOptions,
}
React
import React from 'react'
import { MyModel, preloadMyModel } from '../../../providers'
class MyComponent extends React.PureComponent {
constructor(props) { // not required
super(props)
}
componentWillMount() {
const params = {
...
}
preloadMyModel(params, (response, type) => {
const { ... } = response
if (type === 'SOME_TYPE_ONE') {
...
} else if (type === 'SOME_TYPE_TWO') {
...
} else if (type === 'SOME_TYPE_THREE') {
...
}
return response
})
}
}
1.0.29
5 years ago
1.0.28
6 years ago
1.0.27
6 years ago
1.0.26
6 years ago
1.0.25
6 years ago
1.0.24
6 years ago
1.0.23
6 years ago
1.0.22
6 years ago
1.0.21
6 years ago
1.0.20
6 years ago
1.0.19
6 years ago
1.0.18
6 years ago
1.0.17
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago