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
}
And then you can use the data as you wish
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()
Parse data of data client pro parseData only for getAll to parse the server data Initialize it from contructor function
id prefix for Request (exclude getAll) always use with request functions
change Request options
Set path suffix for all request Path will be cleared after usage
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
Update all Raw data locally
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
useCurrentData will affected by update
!Caution: parseData
will not Effect this method
!Caution: Not like DataClient , Because the dataStructure maybe different , So data list may not be updated only if the return data fit the structure of a single item
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() ;
Result will be prased by parseData
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 Pro ( More Customized solution for different api server )
type RawData = { count: number next?: string previous?: string results: DataItem[] }
type DataItem = { openid: number created: string i1: number no: number modified: string id: string }
parseData
method for data parsing , parseData is a parser to handle the return data, for example:getAll
to parse the resultsconst opts = { parseData: (rawData: RawData):DataItem[] => { return rawData.results; } }
Create with opts to catch error and error msg by defaultimport { DataClientPro } from '@21epub/epub-data-client' const client = new DataClientPro<RawData , DataItem>('http://url.to/data', opts)
const opts = { parseData: (rawData: RawData):DataItem[] => { return rawData.results; } catchError(error){ if(error.status === 400) message.error(error.response.msg); }, catchMsg(msg){ message.error(msg) } } const client = new DataClientPro<DataItem>('http://url.to/data', opts)