@orbcharts/core 3.0.0-alpha.44 → 3.0.0-alpha.46
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +1359 -1334
- package/dist/orbcharts-core.umd.js +2 -2
- package/package.json +1 -1
- package/src/base/createBaseChart.ts +1 -0
- package/src/base/createBasePlugin.ts +20 -14
@@ -1,4 +1,4 @@
|
|
1
|
-
import { takeUntil, map, shareReplay, startWith, Subject, Observable } from 'rxjs'
|
1
|
+
import { of, takeUntil, map, switchMap, shareReplay, startWith, Subject, BehaviorSubject, Observable } from 'rxjs'
|
2
2
|
import type { ChartType, CreateBasePlugin, PluginInitFn, PluginContext } from '../types'
|
3
3
|
import { mergeOptionsWithDefault } from '../utils'
|
4
4
|
|
@@ -10,14 +10,23 @@ function createPlugin <T extends ChartType, PluginName, PluginParams>({ name, de
|
|
10
10
|
}) {
|
11
11
|
|
12
12
|
const destroy$ = new Subject()
|
13
|
-
const
|
14
|
-
const StoreMap = new WeakMap() // 避免memory leak
|
13
|
+
const EntityWeakMap = new WeakMap() // <selection, pluginEntity> 避免只移除selection而沒回收pluginEntity的memory leak
|
15
14
|
let pluginDestroyFn = () => {}
|
16
15
|
let pluginContext: PluginContext<T, PluginName, PluginParams> | undefined
|
17
|
-
|
16
|
+
const mergedDefaultParams$ = new BehaviorSubject(defaultParams)
|
17
|
+
const params$: Subject<Partial<typeof defaultParams>> = new BehaviorSubject({})
|
18
|
+
const fullParams$ = mergedDefaultParams$.pipe(
|
19
|
+
switchMap(mergedDefaultParams => {
|
20
|
+
return params$.pipe(
|
21
|
+
takeUntil(destroy$),
|
22
|
+
map(d => mergeOptionsWithDefault(d, mergedDefaultParams)),
|
23
|
+
)
|
24
|
+
}),
|
25
|
+
shareReplay(1)
|
26
|
+
)
|
18
27
|
|
19
28
|
// 建立plugin實例
|
20
|
-
|
29
|
+
const pluginEntity = {
|
21
30
|
params$,
|
22
31
|
name,
|
23
32
|
defaultParams,
|
@@ -27,7 +36,7 @@ function createPlugin <T extends ChartType, PluginName, PluginParams>({ name, de
|
|
27
36
|
}
|
28
37
|
// 執行
|
29
38
|
pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
|
30
|
-
|
39
|
+
EntityWeakMap.set(pluginContext.selection, pluginContext)
|
31
40
|
},
|
32
41
|
destroy () {
|
33
42
|
pluginDestroyFn()
|
@@ -38,19 +47,16 @@ function createPlugin <T extends ChartType, PluginName, PluginParams>({ name, de
|
|
38
47
|
destroy$.next(undefined)
|
39
48
|
},
|
40
49
|
setPresetParams: (presetParams: Partial<PluginParams>) => {
|
41
|
-
mergedDefaultParams
|
50
|
+
mergedDefaultParams$.next(mergeOptionsWithDefault(presetParams, defaultParams))
|
51
|
+
|
42
52
|
},
|
43
53
|
setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
|
44
54
|
pluginContext = _pluginContext
|
45
|
-
pluginContext.observer.fullParams$ =
|
46
|
-
.pipe(
|
47
|
-
takeUntil(destroy$),
|
48
|
-
startWith({}),
|
49
|
-
map(d => mergeOptionsWithDefault(d, mergedDefaultParams)),
|
50
|
-
shareReplay(1),
|
51
|
-
)
|
55
|
+
pluginContext.observer.fullParams$ = fullParams$
|
52
56
|
}
|
53
57
|
}
|
58
|
+
|
59
|
+
return pluginEntity
|
54
60
|
}
|
55
61
|
|
56
62
|
// 建立plugin類別
|