vscroll 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +283 -273
- package/dist/bundles/vscroll.esm5.js +5553 -5525
- package/dist/bundles/vscroll.esm5.js.map +1 -1
- package/dist/bundles/vscroll.esm5.min.js +2 -2
- package/dist/bundles/vscroll.esm5.min.js.map +1 -1
- package/dist/bundles/vscroll.esm6.js +5040 -5015
- package/dist/bundles/vscroll.esm6.js.map +1 -1
- package/dist/bundles/vscroll.esm6.min.js +2 -2
- package/dist/bundles/vscroll.esm6.min.js.map +1 -1
- package/dist/bundles/vscroll.umd.js +5554 -5526
- package/dist/bundles/vscroll.umd.js.map +1 -1
- package/dist/bundles/vscroll.umd.min.js +2 -2
- package/dist/bundles/vscroll.umd.min.js.map +1 -1
- package/dist/esm2015/classes/adapter/context.js +43 -43
- package/dist/esm2015/classes/adapter/context.js.map +1 -1
- package/dist/esm2015/classes/adapter/props.js +268 -268
- package/dist/esm2015/classes/adapter/props.js.map +1 -1
- package/dist/esm2015/classes/adapter/wanted.js +28 -28
- package/dist/esm2015/classes/adapter/wanted.js.map +1 -1
- package/dist/esm2015/classes/adapter.js +455 -442
- package/dist/esm2015/classes/adapter.js.map +1 -1
- package/dist/esm2015/classes/buffer/cache.js +246 -246
- package/dist/esm2015/classes/buffer/cache.js.map +1 -1
- package/dist/esm2015/classes/buffer/checkCall.js +48 -48
- package/dist/esm2015/classes/buffer/checkCall.js.map +1 -1
- package/dist/esm2015/classes/buffer/defaultSize.js +127 -127
- package/dist/esm2015/classes/buffer/defaultSize.js.map +1 -1
- package/dist/esm2015/classes/buffer.js +342 -342
- package/dist/esm2015/classes/buffer.js.map +1 -1
- package/dist/esm2015/classes/datasource.js +28 -28
- package/dist/esm2015/classes/domRoutines.js +166 -166
- package/dist/esm2015/classes/domRoutines.js.map +1 -1
- package/dist/esm2015/classes/item.js +61 -61
- package/dist/esm2015/classes/item.js.map +1 -1
- package/dist/esm2015/classes/logger.js +186 -186
- package/dist/esm2015/classes/logger.js.map +1 -1
- package/dist/esm2015/classes/paddings.js +72 -72
- package/dist/esm2015/classes/reactive.js +54 -54
- package/dist/esm2015/classes/reactive.js.map +1 -1
- package/dist/esm2015/classes/settings.js +39 -39
- package/dist/esm2015/classes/settings.js.map +1 -1
- package/dist/esm2015/classes/state/clip.js +16 -16
- package/dist/esm2015/classes/state/clip.js.map +1 -1
- package/dist/esm2015/classes/state/cycle.js +60 -60
- package/dist/esm2015/classes/state/cycle.js.map +1 -1
- package/dist/esm2015/classes/state/fetch.js +122 -122
- package/dist/esm2015/classes/state/fetch.js.map +1 -1
- package/dist/esm2015/classes/state/render.js +14 -14
- package/dist/esm2015/classes/state/render.js.map +1 -1
- package/dist/esm2015/classes/state/scroll.js +30 -30
- package/dist/esm2015/classes/state/scroll.js.map +1 -1
- package/dist/esm2015/classes/state.js +59 -59
- package/dist/esm2015/classes/viewport.js +72 -72
- package/dist/esm2015/classes/viewport.js.map +1 -1
- package/dist/esm2015/index.js +8 -8
- package/dist/esm2015/index.js.map +1 -1
- package/dist/esm2015/inputs/adapter.js +230 -230
- package/dist/esm2015/inputs/adapter.js.map +1 -1
- package/dist/esm2015/inputs/common.js +11 -11
- package/dist/esm2015/inputs/common.js.map +1 -1
- package/dist/esm2015/inputs/datasource.js +20 -20
- package/dist/esm2015/inputs/datasource.js.map +1 -1
- package/dist/esm2015/inputs/index.js +6 -6
- package/dist/esm2015/inputs/index.js.map +1 -1
- package/dist/esm2015/inputs/settings.js +146 -146
- package/dist/esm2015/inputs/settings.js.map +1 -1
- package/dist/esm2015/inputs/validation.js +374 -374
- package/dist/esm2015/inputs/validation.js.map +1 -1
- package/dist/esm2015/interfaces/adapter.js +1 -1
- package/dist/esm2015/interfaces/datasource.js +1 -1
- package/dist/esm2015/interfaces/datasource.js.map +1 -1
- package/dist/esm2015/interfaces/index.js +1 -1
- package/dist/esm2015/interfaces/index.js.map +1 -1
- package/dist/esm2015/interfaces/item.js +1 -1
- package/dist/esm2015/interfaces/item.js.map +1 -1
- package/dist/esm2015/interfaces/process.js +1 -1
- package/dist/esm2015/interfaces/routines.js +1 -1
- package/dist/esm2015/interfaces/routines.js.map +1 -1
- package/dist/esm2015/interfaces/settings.js +1 -1
- package/dist/esm2015/interfaces/state.js +1 -1
- package/dist/esm2015/interfaces/validation.js +1 -1
- package/dist/esm2015/interfaces/validation.js.map +1 -1
- package/dist/esm2015/interfaces/workflow.js +1 -1
- package/dist/esm2015/interfaces/workflow.js.map +1 -1
- package/dist/esm2015/processes/adapter/append.js +35 -35
- package/dist/esm2015/processes/adapter/append.js.map +1 -1
- package/dist/esm2015/processes/adapter/check.js +32 -32
- package/dist/esm2015/processes/adapter/check.js.map +1 -1
- package/dist/esm2015/processes/adapter/clip.js +12 -12
- package/dist/esm2015/processes/adapter/clip.js.map +1 -1
- package/dist/esm2015/processes/adapter/fix.js +77 -77
- package/dist/esm2015/processes/adapter/fix.js.map +1 -1
- package/dist/esm2015/processes/adapter/insert.js +73 -73
- package/dist/esm2015/processes/adapter/insert.js.map +1 -1
- package/dist/esm2015/processes/adapter/reload.js +19 -20
- package/dist/esm2015/processes/adapter/reload.js.map +1 -1
- package/dist/esm2015/processes/adapter/remove.js +102 -102
- package/dist/esm2015/processes/adapter/remove.js.map +1 -1
- package/dist/esm2015/processes/adapter/replace.js +39 -39
- package/dist/esm2015/processes/adapter/replace.js.map +1 -1
- package/dist/esm2015/processes/adapter/reset.js +35 -35
- package/dist/esm2015/processes/adapter/reset.js.map +1 -1
- package/dist/esm2015/processes/adapter/update.js +43 -43
- package/dist/esm2015/processes/adapter/update.js.map +1 -1
- package/dist/esm2015/processes/adjust.js +141 -141
- package/dist/esm2015/processes/clip.js +49 -49
- package/dist/esm2015/processes/end.js +52 -52
- package/dist/esm2015/processes/end.js.map +1 -1
- package/dist/esm2015/processes/fetch.js +90 -90
- package/dist/esm2015/processes/fetch.js.map +1 -1
- package/dist/esm2015/processes/index.js +23 -23
- package/dist/esm2015/processes/init.js +14 -14
- package/dist/esm2015/processes/init.js.map +1 -1
- package/dist/esm2015/processes/misc/base.js +30 -30
- package/dist/esm2015/processes/misc/base.js.map +1 -1
- package/dist/esm2015/processes/misc/enums.js +35 -35
- package/dist/esm2015/processes/misc/enums.js.map +1 -1
- package/dist/esm2015/processes/misc/index.js +2 -2
- package/dist/esm2015/processes/misc/index.js.map +1 -1
- package/dist/esm2015/processes/postFetch.js +64 -64
- package/dist/esm2015/processes/postFetch.js.map +1 -1
- package/dist/esm2015/processes/preClip.js +85 -85
- package/dist/esm2015/processes/preClip.js.map +1 -1
- package/dist/esm2015/processes/preFetch.js +240 -240
- package/dist/esm2015/processes/preFetch.js.map +1 -1
- package/dist/esm2015/processes/render.js +54 -54
- package/dist/esm2015/processes/render.js.map +1 -1
- package/dist/esm2015/processes/scroll.js +97 -97
- package/dist/esm2015/processes/scroll.js.map +1 -1
- package/dist/esm2015/processes/start.js +11 -11
- package/dist/esm2015/processes/start.js.map +1 -1
- package/dist/esm2015/scroller.js +75 -69
- package/dist/esm2015/scroller.js.map +1 -1
- package/dist/esm2015/version.js +4 -4
- package/dist/esm2015/version.js.map +1 -1
- package/dist/esm2015/workflow-transducer.js +210 -210
- package/dist/esm2015/workflow-transducer.js.map +1 -1
- package/dist/esm2015/workflow.js +158 -151
- package/dist/esm2015/workflow.js.map +1 -1
- package/dist/esm5/classes/adapter/context.js +50 -50
- package/dist/esm5/classes/adapter/context.js.map +1 -1
- package/dist/esm5/classes/adapter/props.js +268 -268
- package/dist/esm5/classes/adapter/props.js.map +1 -1
- package/dist/esm5/classes/adapter/wanted.js +29 -29
- package/dist/esm5/classes/adapter/wanted.js.map +1 -1
- package/dist/esm5/classes/adapter.js +504 -490
- package/dist/esm5/classes/adapter.js.map +1 -1
- package/dist/esm5/classes/buffer/cache.js +260 -260
- package/dist/esm5/classes/buffer/cache.js.map +1 -1
- package/dist/esm5/classes/buffer/checkCall.js +56 -56
- package/dist/esm5/classes/buffer/checkCall.js.map +1 -1
- package/dist/esm5/classes/buffer/defaultSize.js +145 -145
- package/dist/esm5/classes/buffer/defaultSize.js.map +1 -1
- package/dist/esm5/classes/buffer.js +409 -409
- package/dist/esm5/classes/buffer.js.map +1 -1
- package/dist/esm5/classes/datasource.js +37 -37
- package/dist/esm5/classes/domRoutines.js +182 -182
- package/dist/esm5/classes/domRoutines.js.map +1 -1
- package/dist/esm5/classes/item.js +76 -76
- package/dist/esm5/classes/item.js.map +1 -1
- package/dist/esm5/classes/logger.js +210 -210
- package/dist/esm5/classes/logger.js.map +1 -1
- package/dist/esm5/classes/paddings.js +80 -80
- package/dist/esm5/classes/reactive.js +69 -69
- package/dist/esm5/classes/reactive.js.map +1 -1
- package/dist/esm5/classes/settings.js +47 -47
- package/dist/esm5/classes/settings.js.map +1 -1
- package/dist/esm5/classes/state/clip.js +22 -22
- package/dist/esm5/classes/state/clip.js.map +1 -1
- package/dist/esm5/classes/state/cycle.js +75 -75
- package/dist/esm5/classes/state/cycle.js.map +1 -1
- package/dist/esm5/classes/state/fetch.js +148 -148
- package/dist/esm5/classes/state/fetch.js.map +1 -1
- package/dist/esm5/classes/state/render.js +20 -20
- package/dist/esm5/classes/state/render.js.map +1 -1
- package/dist/esm5/classes/state/scroll.js +32 -32
- package/dist/esm5/classes/state/scroll.js.map +1 -1
- package/dist/esm5/classes/state.js +66 -66
- package/dist/esm5/classes/viewport.js +79 -79
- package/dist/esm5/classes/viewport.js.map +1 -1
- package/dist/esm5/index.js +8 -8
- package/dist/esm5/index.js.map +1 -1
- package/dist/esm5/inputs/adapter.js +231 -231
- package/dist/esm5/inputs/adapter.js.map +1 -1
- package/dist/esm5/inputs/common.js +11 -11
- package/dist/esm5/inputs/common.js.map +1 -1
- package/dist/esm5/inputs/datasource.js +21 -21
- package/dist/esm5/inputs/datasource.js.map +1 -1
- package/dist/esm5/inputs/index.js +6 -6
- package/dist/esm5/inputs/index.js.map +1 -1
- package/dist/esm5/inputs/settings.js +147 -147
- package/dist/esm5/inputs/settings.js.map +1 -1
- package/dist/esm5/inputs/validation.js +396 -396
- package/dist/esm5/inputs/validation.js.map +1 -1
- package/dist/esm5/interfaces/adapter.js +1 -1
- package/dist/esm5/interfaces/datasource.js +1 -1
- package/dist/esm5/interfaces/datasource.js.map +1 -1
- package/dist/esm5/interfaces/index.js +1 -1
- package/dist/esm5/interfaces/index.js.map +1 -1
- package/dist/esm5/interfaces/item.js +1 -1
- package/dist/esm5/interfaces/item.js.map +1 -1
- package/dist/esm5/interfaces/process.js +1 -1
- package/dist/esm5/interfaces/routines.js +1 -1
- package/dist/esm5/interfaces/routines.js.map +1 -1
- package/dist/esm5/interfaces/settings.js +1 -1
- package/dist/esm5/interfaces/state.js +1 -1
- package/dist/esm5/interfaces/validation.js +1 -1
- package/dist/esm5/interfaces/validation.js.map +1 -1
- package/dist/esm5/interfaces/workflow.js +1 -1
- package/dist/esm5/interfaces/workflow.js.map +1 -1
- package/dist/esm5/processes/adapter/append.js +43 -43
- package/dist/esm5/processes/adapter/append.js.map +1 -1
- package/dist/esm5/processes/adapter/check.js +39 -39
- package/dist/esm5/processes/adapter/check.js.map +1 -1
- package/dist/esm5/processes/adapter/clip.js +19 -19
- package/dist/esm5/processes/adapter/clip.js.map +1 -1
- package/dist/esm5/processes/adapter/fix.js +89 -89
- package/dist/esm5/processes/adapter/fix.js.map +1 -1
- package/dist/esm5/processes/adapter/insert.js +81 -81
- package/dist/esm5/processes/adapter/insert.js.map +1 -1
- package/dist/esm5/processes/adapter/reload.js +26 -27
- package/dist/esm5/processes/adapter/reload.js.map +1 -1
- package/dist/esm5/processes/adapter/remove.js +115 -115
- package/dist/esm5/processes/adapter/remove.js.map +1 -1
- package/dist/esm5/processes/adapter/replace.js +47 -47
- package/dist/esm5/processes/adapter/replace.js.map +1 -1
- package/dist/esm5/processes/adapter/reset.js +42 -42
- package/dist/esm5/processes/adapter/reset.js.map +1 -1
- package/dist/esm5/processes/adapter/update.js +59 -59
- package/dist/esm5/processes/adapter/update.js.map +1 -1
- package/dist/esm5/processes/adjust.js +152 -152
- package/dist/esm5/processes/clip.js +60 -60
- package/dist/esm5/processes/end.js +63 -63
- package/dist/esm5/processes/end.js.map +1 -1
- package/dist/esm5/processes/fetch.js +101 -101
- package/dist/esm5/processes/fetch.js.map +1 -1
- package/dist/esm5/processes/index.js +23 -23
- package/dist/esm5/processes/init.js +21 -21
- package/dist/esm5/processes/init.js.map +1 -1
- package/dist/esm5/processes/misc/base.js +44 -44
- package/dist/esm5/processes/misc/base.js.map +1 -1
- package/dist/esm5/processes/misc/enums.js +35 -35
- package/dist/esm5/processes/misc/enums.js.map +1 -1
- package/dist/esm5/processes/misc/index.js +2 -2
- package/dist/esm5/processes/misc/index.js.map +1 -1
- package/dist/esm5/processes/postFetch.js +73 -73
- package/dist/esm5/processes/postFetch.js.map +1 -1
- package/dist/esm5/processes/preClip.js +94 -94
- package/dist/esm5/processes/preClip.js.map +1 -1
- package/dist/esm5/processes/preFetch.js +247 -247
- package/dist/esm5/processes/preFetch.js.map +1 -1
- package/dist/esm5/processes/render.js +63 -63
- package/dist/esm5/processes/render.js.map +1 -1
- package/dist/esm5/processes/scroll.js +107 -107
- package/dist/esm5/processes/scroll.js.map +1 -1
- package/dist/esm5/processes/start.js +18 -18
- package/dist/esm5/processes/start.js.map +1 -1
- package/dist/esm5/scroller.js +81 -73
- package/dist/esm5/scroller.js.map +1 -1
- package/dist/esm5/version.js +4 -4
- package/dist/esm5/version.js.map +1 -1
- package/dist/esm5/workflow-transducer.js +212 -212
- package/dist/esm5/workflow-transducer.js.map +1 -1
- package/dist/esm5/workflow.js +183 -176
- package/dist/esm5/workflow.js.map +1 -1
- package/dist/typings/classes/adapter/context.d.ts +4 -4
- package/dist/typings/classes/adapter/props.d.ts +47 -47
- package/dist/typings/classes/adapter/wanted.d.ts +14 -14
- package/dist/typings/classes/adapter.d.ts +74 -64
- package/dist/typings/classes/buffer/cache.d.ts +95 -95
- package/dist/typings/classes/buffer/checkCall.d.ts +12 -12
- package/dist/typings/classes/buffer/defaultSize.d.ts +32 -32
- package/dist/typings/classes/buffer.d.ts +64 -64
- package/dist/typings/classes/datasource.d.ts +27 -27
- package/dist/typings/classes/domRoutines.d.ts +33 -33
- package/dist/typings/classes/item.d.ts +28 -28
- package/dist/typings/classes/logger.d.ts +28 -28
- package/dist/typings/classes/paddings.d.ts +22 -22
- package/dist/typings/classes/reactive.d.ts +21 -21
- package/dist/typings/classes/settings.d.ts +119 -119
- package/dist/typings/classes/state/clip.d.ts +9 -9
- package/dist/typings/classes/state/cycle.d.ts +29 -29
- package/dist/typings/classes/state/fetch.d.ts +62 -62
- package/dist/typings/classes/state/render.d.ts +9 -9
- package/dist/typings/classes/state/scroll.d.ts +16 -16
- package/dist/typings/classes/state.d.ts +27 -27
- package/dist/typings/classes/viewport.d.ts +32 -32
- package/dist/typings/index.d.ts +9 -9
- package/dist/typings/inputs/adapter.d.ts +5 -5
- package/dist/typings/inputs/common.d.ts +9 -9
- package/dist/typings/inputs/datasource.d.ts +7 -7
- package/dist/typings/inputs/index.d.ts +6 -6
- package/dist/typings/inputs/settings.d.ts +41 -41
- package/dist/typings/inputs/validation.d.ts +83 -83
- package/dist/typings/interfaces/adapter.d.ts +156 -156
- package/dist/typings/interfaces/datasource.d.ts +26 -26
- package/dist/typings/interfaces/index.d.ts +10 -10
- package/dist/typings/interfaces/item.d.ts +8 -8
- package/dist/typings/interfaces/process.d.ts +35 -35
- package/dist/typings/interfaces/routines.d.ts +157 -157
- package/dist/typings/interfaces/settings.d.ts +31 -31
- package/dist/typings/interfaces/state.d.ts +22 -22
- package/dist/typings/interfaces/validation.d.ts +33 -33
- package/dist/typings/interfaces/workflow.d.ts +53 -53
- package/dist/typings/processes/adapter/append.d.ts +14 -14
- package/dist/typings/processes/adapter/check.d.ts +6 -6
- package/dist/typings/processes/adapter/clip.d.ts +7 -7
- package/dist/typings/processes/adapter/fix.d.ts +13 -13
- package/dist/typings/processes/adapter/insert.d.ts +11 -11
- package/dist/typings/processes/adapter/reload.d.ts +6 -6
- package/dist/typings/processes/adapter/remove.d.ts +11 -11
- package/dist/typings/processes/adapter/replace.d.ts +8 -8
- package/dist/typings/processes/adapter/reset.d.ts +7 -7
- package/dist/typings/processes/adapter/update.d.ts +8 -8
- package/dist/typings/processes/adjust.d.ts +10 -10
- package/dist/typings/processes/clip.d.ts +7 -7
- package/dist/typings/processes/end.d.ts +10 -10
- package/dist/typings/processes/fetch.d.ts +18 -18
- package/dist/typings/processes/index.d.ts +23 -23
- package/dist/typings/processes/init.d.ts +7 -7
- package/dist/typings/processes/misc/base.d.ts +4 -4
- package/dist/typings/processes/misc/enums.d.ts +32 -32
- package/dist/typings/processes/misc/index.d.ts +2 -2
- package/dist/typings/processes/postFetch.d.ts +8 -8
- package/dist/typings/processes/preClip.d.ts +12 -12
- package/dist/typings/processes/preFetch.d.ts +17 -17
- package/dist/typings/processes/render.d.ts +9 -9
- package/dist/typings/processes/scroll.d.ts +13 -13
- package/dist/typings/processes/start.d.ts +6 -6
- package/dist/typings/scroller.d.ts +26 -26
- package/dist/typings/version.d.ts +5 -5
- package/dist/typings/workflow-transducer.d.ts +2 -2
- package/dist/typings/workflow.d.ts +28 -28
- package/package.json +68 -68
|
@@ -1,443 +1,456 @@
|
|
|
1
|
-
import { Reactive } from './reactive';
|
|
2
|
-
import { AdapterPropName, AdapterPropType, EMPTY_ITEM, getDefaultAdapterProps, methodPreResult, reactiveConfigStorage } from './adapter/props';
|
|
3
|
-
import { wantedUtils } from './adapter/wanted';
|
|
4
|
-
import { Direction } from '../inputs/index';
|
|
5
|
-
import { AdapterProcess, ProcessStatus } from '../processes/index';
|
|
6
|
-
const ADAPTER_PROPS_STUB = getDefaultAdapterProps();
|
|
7
|
-
const _has = (obj, prop) => typeof obj === 'object' && obj !== null && Object.prototype.hasOwnProperty.call(obj, prop);
|
|
8
|
-
const convertAppendArgs = (prepend, options, eof) => {
|
|
9
|
-
let result = options;
|
|
10
|
-
if (!_has(options, 'items')) {
|
|
11
|
-
const items = !Array.isArray(options) ? [options] : options;
|
|
12
|
-
result = prepend ? { items, bof: eof } : { items, eof: eof };
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
const convertRemoveArgs = (options) => {
|
|
17
|
-
if (!(_has(options, 'predicate') || _has(options, 'indexes'))) {
|
|
18
|
-
const predicate = options;
|
|
19
|
-
options = { predicate };
|
|
20
|
-
}
|
|
21
|
-
return options;
|
|
22
|
-
};
|
|
23
|
-
export class Adapter {
|
|
24
|
-
constructor(context, getWorkflow, logger) {
|
|
25
|
-
this.source = {}; // for Reactive props
|
|
26
|
-
this.box = {}; // for Scalars over Reactive props
|
|
27
|
-
this.demand = {}; // for Scalars on demand
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
-
this.setFirstOrLastVisible = (_) => { };
|
|
30
|
-
this.getWorkflow = getWorkflow;
|
|
31
|
-
this.logger = logger;
|
|
32
|
-
this.relax$ = null;
|
|
33
|
-
this.relaxRun = null;
|
|
34
|
-
this.reloadCounter = 0;
|
|
35
|
-
const contextId = (context === null || context === void 0 ? void 0 : context.id) || -1;
|
|
36
|
-
// public context (if exists) should provide access to Reactive props config by id
|
|
37
|
-
const reactivePropsStore = context && reactiveConfigStorage.get(context.id) || {};
|
|
38
|
-
// the Adapter initialization should not trigger "wanted" props setting;
|
|
39
|
-
// after the initialization is completed, "wanted" functionality must be unblocked
|
|
40
|
-
wantedUtils.setBlock(true, contextId);
|
|
41
|
-
// make array of the original values from public context if present
|
|
42
|
-
const adapterProps = context
|
|
43
|
-
? ADAPTER_PROPS_STUB.map(prop => {
|
|
44
|
-
let value = context[prop.name];
|
|
45
|
-
// if context is augmented, we need to replace external reactive props with inner ones
|
|
46
|
-
if (context.augmented) {
|
|
47
|
-
const reactiveProp = reactivePropsStore[prop.name];
|
|
48
|
-
if (reactiveProp) {
|
|
49
|
-
value = reactiveProp.default; // boolean doesn't matter here
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return (Object.assign(Object.assign({}, prop), { value }));
|
|
53
|
-
})
|
|
54
|
-
: getDefaultAdapterProps();
|
|
55
|
-
// restore default reactive props if they were configured
|
|
56
|
-
Object.entries(reactivePropsStore).forEach(([key, value]) => {
|
|
57
|
-
const prop = adapterProps.find(({ name }) => name === key);
|
|
58
|
-
if (prop && value) {
|
|
59
|
-
prop.value = value.default;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
// Scalar permanent props
|
|
63
|
-
adapterProps
|
|
64
|
-
.filter(({ type, permanent }) => type === AdapterPropType.Scalar && permanent)
|
|
65
|
-
.forEach(({ name, value }) => Object.defineProperty(this, name, {
|
|
66
|
-
configurable: true,
|
|
67
|
-
get: () => value
|
|
68
|
-
}));
|
|
69
|
-
// Reactive props: store original values in "source" container, to avoid extra .get() calls on scalar twins set
|
|
70
|
-
adapterProps
|
|
71
|
-
.filter(prop => prop.type === AdapterPropType.Reactive)
|
|
72
|
-
.forEach(({ name, value }) => {
|
|
73
|
-
this.source[name] = value;
|
|
74
|
-
Object.defineProperty(this, name, {
|
|
75
|
-
configurable: true,
|
|
76
|
-
get: () => this.source[name]
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
// for "wanted" props that can be explicitly requested for the first time after the Adapter initialization,
|
|
80
|
-
// an implicit calculation of the initial value is required;
|
|
81
|
-
// so this method should be called when accessing the "wanted" props through one of the following getters
|
|
82
|
-
const processWanted = (prop) => {
|
|
83
|
-
if (wantedUtils.setBox(prop, contextId)) {
|
|
84
|
-
if ([AdapterPropName.firstVisible, AdapterPropName.firstVisible$].some(n => n === prop.name)) {
|
|
85
|
-
this.setFirstOrLastVisible({ first: true });
|
|
86
|
-
}
|
|
87
|
-
else if ([AdapterPropName.lastVisible, AdapterPropName.lastVisible$].some(n => n === prop.name)) {
|
|
88
|
-
this.setFirstOrLastVisible({ last: true });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
// Scalar props that have Reactive twins
|
|
93
|
-
// 1) reactive props (from "source") should be triggered on set
|
|
94
|
-
// 2) scalars should use "box" container on get
|
|
95
|
-
// 3) "wanted" scalars should also run wanted-related logic on get
|
|
96
|
-
adapterProps
|
|
97
|
-
.filter(prop => prop.type === AdapterPropType.Scalar && !!prop.reactive)
|
|
98
|
-
.forEach((prop) => {
|
|
99
|
-
const { name, value, reactive } = prop;
|
|
100
|
-
this.box[name] = value;
|
|
101
|
-
Object.defineProperty(this, name, {
|
|
102
|
-
configurable: true,
|
|
103
|
-
set: (newValue) => {
|
|
104
|
-
if (newValue !== this.box[name]) {
|
|
105
|
-
this.box[name] = newValue;
|
|
106
|
-
this.source[reactive].set(newValue);
|
|
107
|
-
// need to emit new value through the configured reactive prop if present
|
|
108
|
-
const reactiveProp = reactivePropsStore[reactive];
|
|
109
|
-
if (reactiveProp) {
|
|
110
|
-
reactiveProp.emit(reactiveProp.source, newValue);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
get: () => {
|
|
115
|
-
processWanted(prop);
|
|
116
|
-
return this.box[name];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
// Scalar props on-demand
|
|
121
|
-
// these scalars should use "demand" container
|
|
122
|
-
// setting defaults should be overridden on init()
|
|
123
|
-
adapterProps
|
|
124
|
-
.filter(prop => prop.type === AdapterPropType.Scalar && prop.onDemand)
|
|
125
|
-
.forEach(({ name, value }) => {
|
|
126
|
-
this.demand[name] = value;
|
|
127
|
-
Object.defineProperty(this, name, {
|
|
128
|
-
configurable: true,
|
|
129
|
-
get: () => this.demand[name]
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
if (!context) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
// Adapter public context augmentation
|
|
136
|
-
adapterProps
|
|
137
|
-
.forEach((prop) => {
|
|
138
|
-
const { name, type, value: defaultValue, permanent } = prop;
|
|
139
|
-
let value = this[name];
|
|
140
|
-
if (type === AdapterPropType.Function) {
|
|
141
|
-
value = value.bind(this);
|
|
142
|
-
}
|
|
143
|
-
else if (type === AdapterPropType.WorkflowRunner) {
|
|
144
|
-
value = this.getPromisifiedMethod(value, defaultValue);
|
|
145
|
-
}
|
|
146
|
-
else if (type === AdapterPropType.Reactive && reactivePropsStore[name]) {
|
|
147
|
-
value = context[name];
|
|
148
|
-
}
|
|
149
|
-
else if (name === AdapterPropName.augmented) {
|
|
150
|
-
value = true;
|
|
151
|
-
}
|
|
152
|
-
const nonPermanentScalar = !permanent && type === AdapterPropType.Scalar;
|
|
153
|
-
Object.defineProperty(context, name, {
|
|
154
|
-
configurable: true,
|
|
155
|
-
get: () => {
|
|
156
|
-
processWanted(prop); // consider accessing "wanted" Reactive props
|
|
157
|
-
if (nonPermanentScalar) {
|
|
158
|
-
return this[name]; // non-permanent Scalars should be taken in runtime
|
|
159
|
-
}
|
|
160
|
-
return value; // other props (Reactive/Functions/WorkflowRunners) can be defined once
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
this.externalContext = context;
|
|
165
|
-
wantedUtils.setBlock(false, contextId);
|
|
166
|
-
}
|
|
167
|
-
get workflow() {
|
|
168
|
-
return this.getWorkflow();
|
|
169
|
-
}
|
|
170
|
-
get reloadCount() {
|
|
171
|
-
return this.reloadCounter;
|
|
172
|
-
}
|
|
173
|
-
get reloadId() {
|
|
174
|
-
return this.id + '.' + this.reloadCounter;
|
|
175
|
-
}
|
|
176
|
-
getPromisifiedMethod(method, defaultMethod) {
|
|
177
|
-
return (...args) => this.relax$
|
|
178
|
-
? new Promise(resolve => {
|
|
179
|
-
if (this.relax$) {
|
|
180
|
-
this.relax$.once(value => resolve(value));
|
|
181
|
-
}
|
|
182
|
-
method.apply(this, args);
|
|
183
|
-
})
|
|
184
|
-
: defaultMethod.apply(this, args);
|
|
185
|
-
}
|
|
186
|
-
initialize(buffer, state, viewport, logger, adapterRun
|
|
187
|
-
// buffer
|
|
188
|
-
Object.defineProperty(this.demand, AdapterPropName.itemsCount, {
|
|
189
|
-
get: () => buffer.getVisibleItemsCount()
|
|
190
|
-
});
|
|
191
|
-
Object.defineProperty(this.demand, AdapterPropName.bufferInfo, {
|
|
192
|
-
get: () => ({
|
|
193
|
-
firstIndex: buffer.firstIndex,
|
|
194
|
-
lastIndex: buffer.lastIndex,
|
|
195
|
-
minIndex: buffer.minIndex,
|
|
196
|
-
maxIndex: buffer.maxIndex,
|
|
197
|
-
absMinIndex: buffer.absMinIndex,
|
|
198
|
-
absMaxIndex: buffer.absMaxIndex,
|
|
199
|
-
defaultSize: buffer.defaultSize,
|
|
200
|
-
})
|
|
201
|
-
});
|
|
202
|
-
this.bof = buffer.bof.get();
|
|
203
|
-
buffer.bof.on(bof => this.bof = bof);
|
|
204
|
-
this.eof = buffer.eof.get();
|
|
205
|
-
buffer.eof.on(eof => this.eof = eof);
|
|
206
|
-
// state
|
|
207
|
-
Object.defineProperty(this.demand, AdapterPropName.packageInfo, {
|
|
208
|
-
get: () => state.packageInfo
|
|
209
|
-
});
|
|
210
|
-
this.loopPending = state.cycle.innerLoop.busy.get();
|
|
211
|
-
state.cycle.innerLoop.busy.on(busy => this.loopPending = busy);
|
|
212
|
-
this.isLoading = state.cycle.busy.get();
|
|
213
|
-
state.cycle.busy.on(busy => this.isLoading = busy);
|
|
214
|
-
//viewport
|
|
215
|
-
this.setFirstOrLastVisible = ({ first, last, workflow }) => {
|
|
216
|
-
var _a, _b, _c;
|
|
217
|
-
if ((!first && !last) || ((_a = workflow === null || workflow === void 0 ? void 0 : workflow.call) === null || _a === void 0 ? void 0 : _a.interrupted)) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const token = first ? AdapterPropName.firstVisible : AdapterPropName.lastVisible;
|
|
221
|
-
if (!((_c = wantedUtils.getBox((_b = this.externalContext) === null || _b === void 0 ? void 0 : _b.id)) === null || _c === void 0 ? void 0 : _c[token])) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (buffer.items.some(({ element }) => !element)) {
|
|
225
|
-
logger.log('skipping first/lastVisible set because not all buffered items are rendered at this moment');
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const direction = first ? Direction.backward : Direction.forward;
|
|
229
|
-
const { item } = viewport.getEdgeVisibleItem(buffer.items, direction);
|
|
230
|
-
if (!item || item.element !== this[token].element) {
|
|
231
|
-
this[token] = (item ? item.get() : EMPTY_ITEM);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
// logger
|
|
235
|
-
this.logger = logger;
|
|
236
|
-
// self-pending subscription; set up only on the very first init
|
|
237
|
-
if (adapterRun$) {
|
|
238
|
-
if (!this.relax$) {
|
|
239
|
-
this.relax$ = new Reactive();
|
|
240
|
-
}
|
|
241
|
-
const relax$ = this.relax$;
|
|
242
|
-
adapterRun$.on(({ status, payload }) => {
|
|
243
|
-
let unSubRelax = () => { };
|
|
244
|
-
if (status === ProcessStatus.start) {
|
|
245
|
-
unSubRelax = this.isLoading$.on(value => {
|
|
246
|
-
if (!value) {
|
|
247
|
-
unSubRelax();
|
|
248
|
-
relax$.set({ success: true, immediate: false, details: null });
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
else if (status === ProcessStatus.done || status === ProcessStatus.error) {
|
|
253
|
-
unSubRelax();
|
|
254
|
-
relax$.set({
|
|
255
|
-
success: status !== ProcessStatus.error,
|
|
256
|
-
immediate: true,
|
|
257
|
-
details: status === ProcessStatus.error && payload ? String(payload.error) : null
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
resolve(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
this.
|
|
440
|
-
this.logger.
|
|
441
|
-
|
|
442
|
-
|
|
1
|
+
import { Reactive } from './reactive';
|
|
2
|
+
import { AdapterPropName, AdapterPropType, EMPTY_ITEM, getDefaultAdapterProps, methodPreResult, reactiveConfigStorage } from './adapter/props';
|
|
3
|
+
import { wantedUtils } from './adapter/wanted';
|
|
4
|
+
import { Direction } from '../inputs/index';
|
|
5
|
+
import { AdapterProcess, ProcessStatus } from '../processes/index';
|
|
6
|
+
const ADAPTER_PROPS_STUB = getDefaultAdapterProps();
|
|
7
|
+
const _has = (obj, prop) => typeof obj === 'object' && obj !== null && Object.prototype.hasOwnProperty.call(obj, prop);
|
|
8
|
+
const convertAppendArgs = (prepend, options, eof) => {
|
|
9
|
+
let result = options;
|
|
10
|
+
if (!_has(options, 'items')) {
|
|
11
|
+
const items = !Array.isArray(options) ? [options] : options;
|
|
12
|
+
result = prepend ? { items, bof: eof } : { items, eof: eof };
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const convertRemoveArgs = (options) => {
|
|
17
|
+
if (!(_has(options, 'predicate') || _has(options, 'indexes'))) {
|
|
18
|
+
const predicate = options;
|
|
19
|
+
options = { predicate };
|
|
20
|
+
}
|
|
21
|
+
return options;
|
|
22
|
+
};
|
|
23
|
+
export class Adapter {
|
|
24
|
+
constructor(context, getWorkflow, logger) {
|
|
25
|
+
this.source = {}; // for Reactive props
|
|
26
|
+
this.box = {}; // for Scalars over Reactive props
|
|
27
|
+
this.demand = {}; // for Scalars on demand
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
this.setFirstOrLastVisible = (_) => { };
|
|
30
|
+
this.getWorkflow = getWorkflow;
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.relax$ = null;
|
|
33
|
+
this.relaxRun = null;
|
|
34
|
+
this.reloadCounter = 0;
|
|
35
|
+
const contextId = (context === null || context === void 0 ? void 0 : context.id) || -1;
|
|
36
|
+
// public context (if exists) should provide access to Reactive props config by id
|
|
37
|
+
const reactivePropsStore = context && reactiveConfigStorage.get(context.id) || {};
|
|
38
|
+
// the Adapter initialization should not trigger "wanted" props setting;
|
|
39
|
+
// after the initialization is completed, "wanted" functionality must be unblocked
|
|
40
|
+
wantedUtils.setBlock(true, contextId);
|
|
41
|
+
// make array of the original values from public context if present
|
|
42
|
+
const adapterProps = context
|
|
43
|
+
? ADAPTER_PROPS_STUB.map(prop => {
|
|
44
|
+
let value = context[prop.name];
|
|
45
|
+
// if context is augmented, we need to replace external reactive props with inner ones
|
|
46
|
+
if (context.augmented) {
|
|
47
|
+
const reactiveProp = reactivePropsStore[prop.name];
|
|
48
|
+
if (reactiveProp) {
|
|
49
|
+
value = reactiveProp.default; // boolean doesn't matter here
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return (Object.assign(Object.assign({}, prop), { value }));
|
|
53
|
+
})
|
|
54
|
+
: getDefaultAdapterProps();
|
|
55
|
+
// restore default reactive props if they were configured
|
|
56
|
+
Object.entries(reactivePropsStore).forEach(([key, value]) => {
|
|
57
|
+
const prop = adapterProps.find(({ name }) => name === key);
|
|
58
|
+
if (prop && value) {
|
|
59
|
+
prop.value = value.default;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// Scalar permanent props
|
|
63
|
+
adapterProps
|
|
64
|
+
.filter(({ type, permanent }) => type === AdapterPropType.Scalar && permanent)
|
|
65
|
+
.forEach(({ name, value }) => Object.defineProperty(this, name, {
|
|
66
|
+
configurable: true,
|
|
67
|
+
get: () => value
|
|
68
|
+
}));
|
|
69
|
+
// Reactive props: store original values in "source" container, to avoid extra .get() calls on scalar twins set
|
|
70
|
+
adapterProps
|
|
71
|
+
.filter(prop => prop.type === AdapterPropType.Reactive)
|
|
72
|
+
.forEach(({ name, value }) => {
|
|
73
|
+
this.source[name] = value;
|
|
74
|
+
Object.defineProperty(this, name, {
|
|
75
|
+
configurable: true,
|
|
76
|
+
get: () => this.source[name]
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
// for "wanted" props that can be explicitly requested for the first time after the Adapter initialization,
|
|
80
|
+
// an implicit calculation of the initial value is required;
|
|
81
|
+
// so this method should be called when accessing the "wanted" props through one of the following getters
|
|
82
|
+
const processWanted = (prop) => {
|
|
83
|
+
if (wantedUtils.setBox(prop, contextId)) {
|
|
84
|
+
if ([AdapterPropName.firstVisible, AdapterPropName.firstVisible$].some(n => n === prop.name)) {
|
|
85
|
+
this.setFirstOrLastVisible({ first: true });
|
|
86
|
+
}
|
|
87
|
+
else if ([AdapterPropName.lastVisible, AdapterPropName.lastVisible$].some(n => n === prop.name)) {
|
|
88
|
+
this.setFirstOrLastVisible({ last: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// Scalar props that have Reactive twins
|
|
93
|
+
// 1) reactive props (from "source") should be triggered on set
|
|
94
|
+
// 2) scalars should use "box" container on get
|
|
95
|
+
// 3) "wanted" scalars should also run wanted-related logic on get
|
|
96
|
+
adapterProps
|
|
97
|
+
.filter(prop => prop.type === AdapterPropType.Scalar && !!prop.reactive)
|
|
98
|
+
.forEach((prop) => {
|
|
99
|
+
const { name, value, reactive } = prop;
|
|
100
|
+
this.box[name] = value;
|
|
101
|
+
Object.defineProperty(this, name, {
|
|
102
|
+
configurable: true,
|
|
103
|
+
set: (newValue) => {
|
|
104
|
+
if (newValue !== this.box[name]) {
|
|
105
|
+
this.box[name] = newValue;
|
|
106
|
+
this.source[reactive].set(newValue);
|
|
107
|
+
// need to emit new value through the configured reactive prop if present
|
|
108
|
+
const reactiveProp = reactivePropsStore[reactive];
|
|
109
|
+
if (reactiveProp) {
|
|
110
|
+
reactiveProp.emit(reactiveProp.source, newValue);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
get: () => {
|
|
115
|
+
processWanted(prop);
|
|
116
|
+
return this.box[name];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
// Scalar props on-demand
|
|
121
|
+
// these scalars should use "demand" container
|
|
122
|
+
// setting defaults should be overridden on init()
|
|
123
|
+
adapterProps
|
|
124
|
+
.filter(prop => prop.type === AdapterPropType.Scalar && prop.onDemand)
|
|
125
|
+
.forEach(({ name, value }) => {
|
|
126
|
+
this.demand[name] = value;
|
|
127
|
+
Object.defineProperty(this, name, {
|
|
128
|
+
configurable: true,
|
|
129
|
+
get: () => this.demand[name]
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
if (!context) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Adapter public context augmentation
|
|
136
|
+
adapterProps
|
|
137
|
+
.forEach((prop) => {
|
|
138
|
+
const { name, type, value: defaultValue, permanent } = prop;
|
|
139
|
+
let value = this[name];
|
|
140
|
+
if (type === AdapterPropType.Function) {
|
|
141
|
+
value = value.bind(this);
|
|
142
|
+
}
|
|
143
|
+
else if (type === AdapterPropType.WorkflowRunner) {
|
|
144
|
+
value = this.getPromisifiedMethod(value, defaultValue);
|
|
145
|
+
}
|
|
146
|
+
else if (type === AdapterPropType.Reactive && reactivePropsStore[name]) {
|
|
147
|
+
value = context[name];
|
|
148
|
+
}
|
|
149
|
+
else if (name === AdapterPropName.augmented) {
|
|
150
|
+
value = true;
|
|
151
|
+
}
|
|
152
|
+
const nonPermanentScalar = !permanent && type === AdapterPropType.Scalar;
|
|
153
|
+
Object.defineProperty(context, name, {
|
|
154
|
+
configurable: true,
|
|
155
|
+
get: () => {
|
|
156
|
+
processWanted(prop); // consider accessing "wanted" Reactive props
|
|
157
|
+
if (nonPermanentScalar) {
|
|
158
|
+
return this[name]; // non-permanent Scalars should be taken in runtime
|
|
159
|
+
}
|
|
160
|
+
return value; // other props (Reactive/Functions/WorkflowRunners) can be defined once
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
this.externalContext = context;
|
|
165
|
+
wantedUtils.setBlock(false, contextId);
|
|
166
|
+
}
|
|
167
|
+
get workflow() {
|
|
168
|
+
return this.getWorkflow();
|
|
169
|
+
}
|
|
170
|
+
get reloadCount() {
|
|
171
|
+
return this.reloadCounter;
|
|
172
|
+
}
|
|
173
|
+
get reloadId() {
|
|
174
|
+
return this.id + '.' + this.reloadCounter;
|
|
175
|
+
}
|
|
176
|
+
getPromisifiedMethod(method, defaultMethod) {
|
|
177
|
+
return (...args) => this.relax$
|
|
178
|
+
? new Promise(resolve => {
|
|
179
|
+
if (this.relax$) {
|
|
180
|
+
this.relax$.once(value => resolve(value));
|
|
181
|
+
}
|
|
182
|
+
method.apply(this, args);
|
|
183
|
+
})
|
|
184
|
+
: defaultMethod.apply(this, args);
|
|
185
|
+
}
|
|
186
|
+
initialize({ buffer, state, viewport, logger, adapterRun$, getWorkflow }) {
|
|
187
|
+
// buffer
|
|
188
|
+
Object.defineProperty(this.demand, AdapterPropName.itemsCount, {
|
|
189
|
+
get: () => buffer.getVisibleItemsCount()
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(this.demand, AdapterPropName.bufferInfo, {
|
|
192
|
+
get: () => ({
|
|
193
|
+
firstIndex: buffer.firstIndex,
|
|
194
|
+
lastIndex: buffer.lastIndex,
|
|
195
|
+
minIndex: buffer.minIndex,
|
|
196
|
+
maxIndex: buffer.maxIndex,
|
|
197
|
+
absMinIndex: buffer.absMinIndex,
|
|
198
|
+
absMaxIndex: buffer.absMaxIndex,
|
|
199
|
+
defaultSize: buffer.defaultSize,
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
this.bof = buffer.bof.get();
|
|
203
|
+
buffer.bof.on(bof => this.bof = bof);
|
|
204
|
+
this.eof = buffer.eof.get();
|
|
205
|
+
buffer.eof.on(eof => this.eof = eof);
|
|
206
|
+
// state
|
|
207
|
+
Object.defineProperty(this.demand, AdapterPropName.packageInfo, {
|
|
208
|
+
get: () => state.packageInfo
|
|
209
|
+
});
|
|
210
|
+
this.loopPending = state.cycle.innerLoop.busy.get();
|
|
211
|
+
state.cycle.innerLoop.busy.on(busy => this.loopPending = busy);
|
|
212
|
+
this.isLoading = state.cycle.busy.get();
|
|
213
|
+
state.cycle.busy.on(busy => this.isLoading = busy);
|
|
214
|
+
//viewport
|
|
215
|
+
this.setFirstOrLastVisible = ({ first, last, workflow }) => {
|
|
216
|
+
var _a, _b, _c;
|
|
217
|
+
if ((!first && !last) || ((_a = workflow === null || workflow === void 0 ? void 0 : workflow.call) === null || _a === void 0 ? void 0 : _a.interrupted)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const token = first ? AdapterPropName.firstVisible : AdapterPropName.lastVisible;
|
|
221
|
+
if (!((_c = wantedUtils.getBox((_b = this.externalContext) === null || _b === void 0 ? void 0 : _b.id)) === null || _c === void 0 ? void 0 : _c[token])) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (buffer.items.some(({ element }) => !element)) {
|
|
225
|
+
logger.log('skipping first/lastVisible set because not all buffered items are rendered at this moment');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const direction = first ? Direction.backward : Direction.forward;
|
|
229
|
+
const { item } = viewport.getEdgeVisibleItem(buffer.items, direction);
|
|
230
|
+
if (!item || item.element !== this[token].element) {
|
|
231
|
+
this[token] = (item ? item.get() : EMPTY_ITEM);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
// logger
|
|
235
|
+
this.logger = logger;
|
|
236
|
+
// self-pending subscription; set up only on the very first init
|
|
237
|
+
if (adapterRun$) {
|
|
238
|
+
if (!this.relax$) {
|
|
239
|
+
this.relax$ = new Reactive();
|
|
240
|
+
}
|
|
241
|
+
const relax$ = this.relax$;
|
|
242
|
+
adapterRun$.on(({ status, payload }) => {
|
|
243
|
+
let unSubRelax = () => { };
|
|
244
|
+
if (status === ProcessStatus.start) {
|
|
245
|
+
unSubRelax = this.isLoading$.on(value => {
|
|
246
|
+
if (!value) {
|
|
247
|
+
unSubRelax();
|
|
248
|
+
relax$.set({ success: true, immediate: false, details: null });
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else if (status === ProcessStatus.done || status === ProcessStatus.error) {
|
|
253
|
+
unSubRelax();
|
|
254
|
+
relax$.set({
|
|
255
|
+
success: status !== ProcessStatus.error,
|
|
256
|
+
immediate: true,
|
|
257
|
+
details: status === ProcessStatus.error && payload ? String(payload.error) : null
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
// workflow getter
|
|
263
|
+
if (getWorkflow) {
|
|
264
|
+
this.getWorkflow = getWorkflow;
|
|
265
|
+
}
|
|
266
|
+
// init
|
|
267
|
+
this.init = true;
|
|
268
|
+
}
|
|
269
|
+
dispose() {
|
|
270
|
+
if (this.relax$) {
|
|
271
|
+
this.relax$.dispose();
|
|
272
|
+
}
|
|
273
|
+
if (this.externalContext) {
|
|
274
|
+
this.resetContext();
|
|
275
|
+
}
|
|
276
|
+
Object.getOwnPropertyNames(this).forEach(prop => {
|
|
277
|
+
delete this[prop];
|
|
278
|
+
});
|
|
279
|
+
this.disposed = true;
|
|
280
|
+
}
|
|
281
|
+
resetContext() {
|
|
282
|
+
var _a;
|
|
283
|
+
const reactiveStore = reactiveConfigStorage.get((_a = this.externalContext) === null || _a === void 0 ? void 0 : _a.id);
|
|
284
|
+
ADAPTER_PROPS_STUB
|
|
285
|
+
.forEach(({ type, permanent, name, value }) => {
|
|
286
|
+
// assign initial values to non-reactive non-permanent props
|
|
287
|
+
if (type !== AdapterPropType.Reactive && !permanent) {
|
|
288
|
+
Object.defineProperty(this.externalContext, name, {
|
|
289
|
+
configurable: true,
|
|
290
|
+
get: () => value
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
// reset reactive props
|
|
294
|
+
if (type === AdapterPropType.Reactive && reactiveStore) {
|
|
295
|
+
const property = reactiveStore[name];
|
|
296
|
+
if (property) {
|
|
297
|
+
property.default.reset();
|
|
298
|
+
property.emit(property.source, property.default.get());
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
304
|
+
reset(options) {
|
|
305
|
+
this.reloadCounter++;
|
|
306
|
+
this.logger.logAdapterMethod('reset', options, ` of ${this.reloadId}`);
|
|
307
|
+
this.workflow.call({
|
|
308
|
+
process: AdapterProcess.reset,
|
|
309
|
+
status: ProcessStatus.start,
|
|
310
|
+
payload: { options }
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
314
|
+
reload(options) {
|
|
315
|
+
this.reloadCounter++;
|
|
316
|
+
this.logger.logAdapterMethod('reload', options, ` of ${this.reloadId}`);
|
|
317
|
+
this.workflow.call({
|
|
318
|
+
process: AdapterProcess.reload,
|
|
319
|
+
status: ProcessStatus.start,
|
|
320
|
+
payload: { options }
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
324
|
+
append(_options, eof) {
|
|
325
|
+
const options = convertAppendArgs(false, _options, eof); // support old signature
|
|
326
|
+
this.logger.logAdapterMethod('append', [options.items, options.eof]);
|
|
327
|
+
this.workflow.call({
|
|
328
|
+
process: AdapterProcess.append,
|
|
329
|
+
status: ProcessStatus.start,
|
|
330
|
+
payload: { options }
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
|
+
prepend(_options, bof) {
|
|
335
|
+
const options = convertAppendArgs(true, _options, bof); // support old signature
|
|
336
|
+
this.logger.logAdapterMethod('prepend', [options.items, options.bof]);
|
|
337
|
+
this.workflow.call({
|
|
338
|
+
process: AdapterProcess.prepend,
|
|
339
|
+
status: ProcessStatus.start,
|
|
340
|
+
payload: { options }
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
+
check() {
|
|
345
|
+
this.logger.logAdapterMethod('check');
|
|
346
|
+
this.workflow.call({
|
|
347
|
+
process: AdapterProcess.check,
|
|
348
|
+
status: ProcessStatus.start
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
352
|
+
remove(options) {
|
|
353
|
+
options = convertRemoveArgs(options); // support old signature
|
|
354
|
+
this.logger.logAdapterMethod('remove', options);
|
|
355
|
+
this.workflow.call({
|
|
356
|
+
process: AdapterProcess.remove,
|
|
357
|
+
status: ProcessStatus.start,
|
|
358
|
+
payload: { options }
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
362
|
+
clip(options) {
|
|
363
|
+
this.logger.logAdapterMethod('clip', options);
|
|
364
|
+
this.workflow.call({
|
|
365
|
+
process: AdapterProcess.clip,
|
|
366
|
+
status: ProcessStatus.start,
|
|
367
|
+
payload: { options }
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
|
+
insert(options) {
|
|
372
|
+
this.logger.logAdapterMethod('insert', options);
|
|
373
|
+
this.workflow.call({
|
|
374
|
+
process: AdapterProcess.insert,
|
|
375
|
+
status: ProcessStatus.start,
|
|
376
|
+
payload: { options }
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
380
|
+
replace(options) {
|
|
381
|
+
this.logger.logAdapterMethod('replace', options);
|
|
382
|
+
this.workflow.call({
|
|
383
|
+
process: AdapterProcess.replace,
|
|
384
|
+
status: ProcessStatus.start,
|
|
385
|
+
payload: { options }
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
389
|
+
update(options) {
|
|
390
|
+
this.logger.logAdapterMethod('update', options);
|
|
391
|
+
this.workflow.call({
|
|
392
|
+
process: AdapterProcess.update,
|
|
393
|
+
status: ProcessStatus.start,
|
|
394
|
+
payload: { options }
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
398
|
+
fix(options) {
|
|
399
|
+
this.logger.logAdapterMethod('fix', options);
|
|
400
|
+
this.workflow.call({
|
|
401
|
+
process: AdapterProcess.fix,
|
|
402
|
+
status: ProcessStatus.start,
|
|
403
|
+
payload: { options }
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
relaxUnchained(callback, reloadId) {
|
|
407
|
+
const runCallback = () => typeof callback === 'function' && reloadId === this.reloadId && callback();
|
|
408
|
+
if (!this.isLoading) {
|
|
409
|
+
runCallback();
|
|
410
|
+
}
|
|
411
|
+
return new Promise(resolve => {
|
|
412
|
+
if (!this.isLoading) {
|
|
413
|
+
resolve(true);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
this.isLoading$.once(() => {
|
|
417
|
+
runCallback();
|
|
418
|
+
resolve(false);
|
|
419
|
+
});
|
|
420
|
+
}).then(immediate => {
|
|
421
|
+
var _a, _b;
|
|
422
|
+
if (this.disposed) {
|
|
423
|
+
return {
|
|
424
|
+
immediate,
|
|
425
|
+
success: false,
|
|
426
|
+
details: 'Adapter was disposed'
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const success = reloadId === this.reloadId;
|
|
430
|
+
(_b = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log) === null || _b === void 0 ? void 0 : _b.call(_a, () => !success ? `relax promise cancelled due to ${reloadId} != ${this.reloadId}` : void 0);
|
|
431
|
+
return {
|
|
432
|
+
immediate,
|
|
433
|
+
success,
|
|
434
|
+
details: !success ? 'Interrupted by reload or reset' : null
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
relax(callback) {
|
|
439
|
+
const reloadId = this.reloadId;
|
|
440
|
+
this.logger.logAdapterMethod('relax', callback, ` of ${reloadId}`);
|
|
441
|
+
if (!this.init) {
|
|
442
|
+
return Promise.resolve(methodPreResult);
|
|
443
|
+
}
|
|
444
|
+
return this.relaxRun = this.relaxRun
|
|
445
|
+
? this.relaxRun.then(() => this.relaxUnchained(callback, reloadId))
|
|
446
|
+
: this.relaxUnchained(callback, reloadId).then((result) => {
|
|
447
|
+
this.relaxRun = null;
|
|
448
|
+
return result;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
showLog() {
|
|
452
|
+
this.logger.logAdapterMethod('showLog');
|
|
453
|
+
this.logger.logForce();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
443
456
|
//# sourceMappingURL=adapter.js.map
|