king-crimson
A library that provides classes for managing sequential data.
Installation
npm install king-crimson
Usage
The following two management classes are provided.
DateTimeDataManager
: Manage data with datetime information.IntervalDataManager
: Manages data with interval information.
DateTimeDataManager
;;; // Event data to manage // Create an async function to call API; // Create instance; // Execute fetch;ddm.fetchdatetime; // Cancel fetchddm.cansel; // Search data;;
Config
Property | Type | Description |
---|---|---|
fetchFn | (period: Interval) => { promise: Promise<T[]>, cancel: () => void } |
Methods that request data and methods that cancel requests. |
itemKey | (item: T) => any |
Key value of AVL tree. |
Options
Property | Type | Default | Description |
---|---|---|---|
fetchDuration | Duration |
Duration.fromObject({ hour: 24 }) |
Duration for making data requests in batch. |
requestDurationLimit | Duration |
Duration.fromObject({ minute: 180 }) |
Duration limit for one data request. |
updateInterceptor | ((payload: { items: T[], period: Interval }) => { items: T[], period: Interval }) | null |
null |
Interceptor that transforms the payload before handling the update event. |
IntervalDataManager
;;; // Event data to manage // Create an async function to call API; // Create instance; // Execute fetch;idm.fetchdatetime; // Cancel fetchidm.cansel; // Search data;; // Search for data that includes a specified datetimedata = searchOndatetime;
Config
Property | Type | Description |
---|---|---|
fetchFn | (period: Interval) => { promise: Promise<T[]>, cancel: () => void } |
Methods that request data and methods that cancel requests. |
itemKey | (item: T) => any |
Key value of AVL tree. |
itemTimestamp | (item: T) => number |
Method that returns the timestamp of data in Unixtime in milliseconds. |
itemDuration | (item: T) => number |
Method that returns duration of data in milliseconds. |
Options
Property | Type | Default | Description |
---|---|---|---|
fetchDuration | Duration |
Duration.fromObject({ hour: 24 }) |
Duration for making data requests in batch. |
requestDurationLimit | Duration |
Duration.fromObject({ minute: 180 }) |
Duration limit for one data request. |
updateInterceptor | ((payload: { items: T[], period: Interval }) => { items: T[], period: Interval }) | null |
null |
Interceptor that transforms the payload before handling the update event. |
Event
Both classes emit the following events:
Event | Payload | Description |
---|---|---|
update | { items: T[], period: Interval } |
When each data fetch is completed, the acquired data and the acquisition period are notified. |