Use current data of data client Current data is an object as below
{
"i1": 12,
"openid": 8,
"id": "5fa50894b550865b04515e71",
"modified": "2020-11-06 16:26",
"created": "2020-11-06 16:25"
}
loading statu hooks for Current Data
Hooks of result data Data structure as below:
[
{
"openid": 8,
"created": "2020-11-06 16:25",
"i1": 12,
"no": 1,
"modified": "2020-11-06 16:26",
"id": "5fa50894b550865b04515e71"
}
]
loading statu hooks for Data
Hooks for get query object Can be used with .query() ,async data change
Hooks of rawData The Demo rawData structure as below:
{
"numpages": 1,
"sum": 1,
"results": [
{
"openid": 8,
"created": "2020-11-06 16:25",
"i1": 12,
"no": 1,
"modified": "2020-11-06 16:26",
"id": "5fa50894b550865b04515e71"
}
],
"facet": [],
"page": 1,
"size": 1
}
Origin url of data client , Use with urlReset()
Url of data client
CurrentData loading rxjs subject Custom trigger on demand Use with fetchCurrent() automatically
Data loading$ rxjs/BehaviorSubject Custom trigger dataLoading$ state Automatically trigger by getAll()
id prefix for Request (exclude getAll) always use with request functions
change Request options
Set page for getAll() only
Set path suffix for all request Path will be cleared after usage
Set the query args only for getAll function
Set size only for getAll()
size / per page to fetch data
Change client main url Can reset by this.urlReset()
Reset to origin client url
Append a single data to the end of the local data list Without any sync with server
Delete a single Data from local
Patch a local data object value without sync server request
Update all data locally !Caution: This function only changes the data list without modify the 'sum' value
clear Id and path after request
change current Use it with fetchCurrent to fetch current item's data from server Or use fetchCurrentLocal from this.data Id params will be cleared after using.
fetch current data from this.data
A low level request use as what you want . It return a rxjs/ajax observer
rxjs/ajax observer
A low level request function . Returns a request Promise It will not preserve the return data
fetch Current Item data from server Allowed path suffix automately preserve data to this._currentData and this.data useCurrentData will affected by update
use to get a single data or other usage will not preserve the data
await client.id('12345').get() // get object by id '12345'
Current Catch after request
await client.id('12345').get().catch(err => console.log(error.response.msg))
fetch All context datas preserve the data to this.rawData and this.data Every fetch success for change the data
await client.getAll() // will fetch from http://url
await client.getAll().catch(err=> console.log(err)) // fetch for custom error catch
You can also change url temporary or make path suffix to the url, id() not support
await client.url('http://newurl").getAll() // fetch from url `http://newurl`
await client.path('all/').getAll() // fetch from url `http://url/all/`
getAll() with page , size and query arguments
await client.page(2).size(20).query({query:"demo"}).getAll() ;
fetch more context datas from server append these data to this.data preserve the data to this.rawData and this.data Every fetch success for change the data Scroll a container to load more page datas
await client.page(2).getMore() // will fetch from http://url
await client.getMore() // not page params , asume this._page is 1 , then it will automatically load data from page 2
await client.getMore().catch(err=> console.log(err)) // fetch for custom error catch
You can also change url temporary or make path suffix to the url, id() not support
await client.url('http://newurl").getMore() // fetch from url `http://newurl`
await client.path('all/').getMore() // fetch from url `http://url/all/`
getMore() with page , size and query arguments
await client.page(2).size(20).query({query:"demo"}).getMore() ;
Custom the methods to handle the data callback , You can append or prepend the data to origin or make any validation
Patch partial data to server
restful api to post a new object
Rest api to put
_options of data client TODO: acceptMethods: methods to accept in request contentType: You can change de mode for request addBackSlash: If the url will end with a backSlash
Generated using TypeDoc
Data client
type DataItem = { openid: number created: string i1: number no: number modified: string id: string }
Create with opts to catch error and error msg by defaultimport { DataClient } from '@21epub/epub-data-client' const client = new DataClient<DataItem>('http://url.to/data')
const opts = { catchError(error){ if(error.status === 400) message.error(error.response.msg); }, catchMsg(msg){ message.error(msg) } } const client = new DataClient<DataItem>('http://url.to/data', opts)