@formvk/core 0.1.0 → 1.0.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +63 -0
  3. package/package.json +8 -4
  4. package/src/__tests__/array.spec.ts +0 -168
  5. package/src/__tests__/effects.spec.ts +0 -595
  6. package/src/__tests__/externals.spec.ts +0 -101
  7. package/src/__tests__/field.spec.ts +0 -572
  8. package/src/__tests__/form.spec.ts +0 -720
  9. package/src/__tests__/graph.spec.ts +0 -56
  10. package/src/__tests__/heart.spec.ts +0 -60
  11. package/src/__tests__/internals.spec.ts +0 -138
  12. package/src/__tests__/lifecycle.spec.ts +0 -51
  13. package/src/__tests__/object.spec.ts +0 -107
  14. package/src/__tests__/query.spec.ts +0 -100
  15. package/src/__tests__/shared.ts +0 -10
  16. package/src/__tests__/typed.spec.ts +0 -52
  17. package/src/__tests__/void.spec.ts +0 -163
  18. package/src/effects/index.ts +0 -2
  19. package/src/effects/onFieldEffects.ts +0 -97
  20. package/src/effects/onFormEffects.ts +0 -48
  21. package/src/global.d.ts +0 -8
  22. package/src/index.ts +0 -4
  23. package/src/models/ArrayField.ts +0 -133
  24. package/src/models/BaseField.ts +0 -359
  25. package/src/models/Field.ts +0 -450
  26. package/src/models/Form.ts +0 -586
  27. package/src/models/Graph.ts +0 -56
  28. package/src/models/Heart.ts +0 -75
  29. package/src/models/LifeCycle.ts +0 -42
  30. package/src/models/ObjectField.ts +0 -48
  31. package/src/models/Query.ts +0 -97
  32. package/src/models/VoidField.ts +0 -64
  33. package/src/models/index.ts +0 -9
  34. package/src/models/types.ts +0 -9
  35. package/src/shared/checkers.ts +0 -85
  36. package/src/shared/constants.ts +0 -60
  37. package/src/shared/effective.ts +0 -69
  38. package/src/shared/externals.ts +0 -65
  39. package/src/shared/internals.ts +0 -965
  40. package/src/types.ts +0 -401
  41. package/tsconfig.build.json +0 -9
  42. package/tsconfig.json +0 -4
  43. package/vite.config.ts +0 -46
@@ -1,586 +0,0 @@
1
- import { action, autorun, batch, computed, observable, observe, shallow, shallowRef } from '@formvk/reactive'
2
- import type { Dispose } from '@formvk/reactive'
3
- import type { FormPathPattern } from '@formvk/shared'
4
- import { FormPath, globalThisPolyfill, isArr, isObj, isPlainObj, isValid, merge, uid } from '@formvk/shared'
5
-
6
- import { isVoidField } from '../shared/checkers'
7
- import { runEffects } from '../shared/effective'
8
- import {
9
- batchReset,
10
- batchSubmit,
11
- batchValidate,
12
- createBatchStateGetter,
13
- createBatchStateSetter,
14
- createStateGetter,
15
- createStateSetter,
16
- getValidFormValues,
17
- setLoading,
18
- setSubmitting,
19
- setValidating,
20
- triggerFormInitialValuesChange,
21
- triggerFormValuesChange,
22
- } from '../shared/internals'
23
- import type {
24
- FormDisplayTypes,
25
- FormPatternTypes,
26
- HeartSubscriber,
27
- IFieldFactoryProps,
28
- IFieldResetOptions,
29
- IFieldStateGetter,
30
- IFieldStateSetter,
31
- IFormFeedback,
32
- IFormFields,
33
- IFormGraph,
34
- IFormMergeStrategy,
35
- IFormProps,
36
- IFormRequests,
37
- IFormState,
38
- IModelGetter,
39
- IModelSetter,
40
- ISearchFeedback,
41
- IVoidFieldFactoryProps,
42
- } from '../types'
43
- import { LifeCycleTypes } from '../types'
44
- import { ArrayField } from './ArrayField'
45
- import { Field } from './Field'
46
- import { Graph } from './Graph'
47
- import { Heart } from './Heart'
48
- import { ObjectField } from './ObjectField'
49
- import { Query } from './Query'
50
- import { VoidField } from './VoidField'
51
-
52
- const DEV_TOOLS_HOOK = '__FORMILY_DEV_TOOLS_HOOK__'
53
-
54
- export class Form<ValueType extends object = any> {
55
- displayName = 'Form'
56
- id = ''
57
- @shallowRef accessor initialized = false
58
- @shallowRef accessor validating: boolean | undefined = false
59
- @shallowRef accessor submitting: boolean | undefined = false
60
- @shallowRef accessor loading: boolean | undefined = false
61
- @shallowRef accessor modified = false
62
- @shallowRef accessor pattern: FormPatternTypes = 'editable'
63
- @shallowRef accessor display: FormDisplayTypes = 'visible'
64
- @observable accessor values: ValueType = {} as ValueType
65
- @observable accessor initialValues: ValueType = {} as ValueType
66
- @shallowRef accessor mounted = false
67
- @shallowRef accessor unmounted = false
68
- props: IFormProps<ValueType> = {}
69
- heart!: Heart
70
- graph!: Graph
71
- @shallow accessor fields: IFormFields = {}
72
- requests: IFormRequests = {}
73
- @shallow accessor indexes: Record<string, string> = {}
74
- disposers: (() => void)[] = []
75
-
76
- constructor(props: IFormProps<ValueType> = {}) {
77
- this.initialize(props)
78
- this.makeReactive()
79
- this.makeValues()
80
- this.onInit()
81
- }
82
-
83
- protected initialize(props: IFormProps<ValueType>) {
84
- this.id = uid()
85
- this.props = { ...props }
86
- this.initialized = false
87
- this.submitting = false
88
- this.validating = false
89
- this.loading = false
90
- this.modified = false
91
- this.mounted = false
92
- this.unmounted = false
93
- this.display = this.props.display || 'visible'
94
- this.pattern = this.props.pattern || 'editable'
95
- this.editable = this.props.editable!
96
- this.disabled = this.props.disabled!
97
- this.readOnly = this.props.readOnly!
98
- this.readPretty = this.props.readPretty!
99
- this.visible = this.props.visible!
100
- this.hidden = this.props.hidden!
101
- this.graph = new Graph(this)
102
- this.heart = new Heart({
103
- lifecycles: this.lifecycles,
104
- context: this,
105
- })
106
- }
107
-
108
- protected makeValues() {
109
- this.values = getValidFormValues(this.props.values)
110
- this.initialValues = getValidFormValues(this.props.initialValues)
111
- }
112
-
113
- protected makeReactive() {
114
- // 装饰器架构下 Form 实例本身不是代理,需要分别观察 values / initialValues,
115
- // 并用 autorun 跟踪引用变化,overwrite 重新赋值后自动重新订阅
116
- let disposeValues: Dispose | undefined
117
- let disposeInitialValues: Dispose | undefined
118
- this.disposers.push(
119
- autorun(() => {
120
- disposeValues?.()
121
- disposeValues = observe(
122
- this.values,
123
- change => {
124
- triggerFormValuesChange(this, change)
125
- },
126
- true
127
- )
128
- }),
129
- autorun(() => {
130
- disposeInitialValues?.()
131
- disposeInitialValues = observe(
132
- this.initialValues,
133
- change => {
134
- triggerFormInitialValuesChange(this, change)
135
- },
136
- true
137
- )
138
- }),
139
- () => {
140
- disposeValues?.()
141
- disposeInitialValues?.()
142
- }
143
- )
144
- }
145
-
146
- @computed
147
- get valid() {
148
- return !this.invalid
149
- }
150
-
151
- @computed
152
- get invalid() {
153
- return this.errors.length > 0
154
- }
155
-
156
- @computed
157
- get errors() {
158
- return this.queryFeedbacks({
159
- type: 'error',
160
- })
161
- }
162
-
163
- @computed
164
- get warnings() {
165
- return this.queryFeedbacks({
166
- type: 'warning',
167
- })
168
- }
169
-
170
- @computed
171
- get successes() {
172
- return this.queryFeedbacks({
173
- type: 'success',
174
- })
175
- }
176
-
177
- get lifecycles() {
178
- return runEffects(this, this.props.effects)
179
- }
180
-
181
- @computed
182
- get hidden() {
183
- return this.display === 'hidden'
184
- }
185
-
186
- @computed
187
- get visible() {
188
- return this.display === 'visible'
189
- }
190
-
191
- set hidden(hidden: boolean) {
192
- if (!isValid(hidden)) return
193
- if (hidden) {
194
- this.display = 'hidden'
195
- } else {
196
- this.display = 'visible'
197
- }
198
- }
199
-
200
- set visible(visible: boolean) {
201
- if (!isValid(visible)) return
202
- if (visible) {
203
- this.display = 'visible'
204
- } else {
205
- this.display = 'none'
206
- }
207
- }
208
-
209
- @computed
210
- get editable() {
211
- return this.pattern === 'editable'
212
- }
213
-
214
- set editable(editable: boolean) {
215
- if (!isValid(editable)) return
216
- if (editable) {
217
- this.pattern = 'editable'
218
- } else {
219
- this.pattern = 'readPretty'
220
- }
221
- }
222
-
223
- @computed
224
- get readOnly() {
225
- return this.pattern === 'readOnly'
226
- }
227
-
228
- set readOnly(readOnly) {
229
- if (!isValid(readOnly)) return
230
- if (readOnly) {
231
- this.pattern = 'readOnly'
232
- } else {
233
- this.pattern = 'editable'
234
- }
235
- }
236
-
237
- @computed
238
- get disabled() {
239
- return this.pattern === 'disabled'
240
- }
241
-
242
- set disabled(disabled) {
243
- if (!isValid(disabled)) return
244
- if (disabled) {
245
- this.pattern = 'disabled'
246
- } else {
247
- this.pattern = 'editable'
248
- }
249
- }
250
-
251
- @computed
252
- get readPretty() {
253
- return this.pattern === 'readPretty'
254
- }
255
-
256
- set readPretty(readPretty) {
257
- if (!isValid(readPretty)) return
258
- if (readPretty) {
259
- this.pattern = 'readPretty'
260
- } else {
261
- this.pattern = 'editable'
262
- }
263
- }
264
-
265
- /** 创建字段 **/
266
-
267
- createField(props: IFieldFactoryProps<any, any>): Field | undefined {
268
- const address = FormPath.parse(props.basePath).concat(props.name)
269
- const identifier = address.toString()
270
- if (!identifier) return
271
- if (!this.fields[identifier] || this.props.designable) {
272
- batch(() => {
273
- new Field(address, props, this, this.props.designable)
274
- })
275
- this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
276
- }
277
- return this.fields[identifier] as any
278
- }
279
-
280
- createArrayField(props: IFieldFactoryProps<any, any>): ArrayField | undefined {
281
- const address = FormPath.parse(props.basePath).concat(props.name)
282
- const identifier = address.toString()
283
- if (!identifier) return
284
- if (!this.fields[identifier] || this.props.designable) {
285
- batch(() => {
286
- new ArrayField(
287
- address,
288
- {
289
- ...props,
290
- value: isArr(props.value) ? props.value : [],
291
- },
292
- this,
293
- this.props.designable
294
- )
295
- })
296
- this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
297
- }
298
- return this.fields[identifier] as ArrayField
299
- }
300
-
301
- createObjectField(props: IFieldFactoryProps<any, any>): ObjectField | undefined {
302
- const address = FormPath.parse(props.basePath).concat(props.name)
303
- const identifier = address.toString()
304
- if (!identifier) return
305
- if (!this.fields[identifier] || this.props.designable) {
306
- batch(() => {
307
- new ObjectField(
308
- address,
309
- {
310
- ...props,
311
- value: isObj(props.value) ? props.value : {},
312
- },
313
- this,
314
- this.props.designable
315
- )
316
- })
317
- this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
318
- }
319
- return this.fields[identifier] as ObjectField
320
- }
321
-
322
- createVoidField(props: IVoidFieldFactoryProps<any, any>): VoidField | undefined {
323
- const address = FormPath.parse(props.basePath).concat(props.name)
324
- const identifier = address.toString()
325
- if (!identifier) return
326
- if (!this.fields[identifier] || this.props.designable) {
327
- batch(() => {
328
- new VoidField(address, props, this, this.props.designable)
329
- })
330
- this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
331
- }
332
- return this.fields[identifier] as VoidField
333
- }
334
-
335
- /** 状态操作模型 **/
336
-
337
- @action
338
- setValues = (values: any, strategy: IFormMergeStrategy = 'merge') => {
339
- if (!isPlainObj(values)) return
340
- if (strategy === 'merge' || strategy === 'deepMerge') {
341
- merge(this.values, values, {
342
- // never reach
343
- arrayMerge: (target, source) => source,
344
- assign: true,
345
- })
346
- } else if (strategy === 'shallowMerge') {
347
- Object.assign(this.values, values)
348
- } else {
349
- this.values = values as any
350
- }
351
- }
352
-
353
- @action
354
- setInitialValues = (initialValues: any, strategy: IFormMergeStrategy = 'merge') => {
355
- if (!isPlainObj(initialValues)) return
356
- if (strategy === 'merge' || strategy === 'deepMerge') {
357
- merge(this.initialValues, initialValues, {
358
- // never reach
359
- arrayMerge: (target, source) => source,
360
- assign: true,
361
- })
362
- } else if (strategy === 'shallowMerge') {
363
- Object.assign(this.initialValues, initialValues)
364
- } else {
365
- this.initialValues = initialValues as any
366
- }
367
- }
368
-
369
- @action
370
- setValuesIn = (pattern: FormPathPattern, value: any) => {
371
- FormPath.setIn(this.values, pattern, value)
372
- }
373
-
374
- @action
375
- deleteValuesIn = (pattern: FormPathPattern) => {
376
- FormPath.deleteIn(this.values, pattern)
377
- }
378
-
379
- existValuesIn = (pattern: FormPathPattern) => {
380
- return FormPath.existIn(this.values, pattern)
381
- }
382
-
383
- getValuesIn = (pattern: FormPathPattern) => {
384
- return FormPath.getIn(this.values, pattern)
385
- }
386
-
387
- @action
388
- setInitialValuesIn = (pattern: FormPathPattern, initialValue: any) => {
389
- FormPath.setIn(this.initialValues, pattern, initialValue)
390
- }
391
-
392
- @action
393
- deleteInitialValuesIn = (pattern: FormPathPattern) => {
394
- FormPath.deleteIn(this.initialValues, pattern)
395
- }
396
-
397
- existInitialValuesIn = (pattern: FormPathPattern) => {
398
- return FormPath.existIn(this.initialValues, pattern)
399
- }
400
-
401
- getInitialValuesIn = (pattern: FormPathPattern) => {
402
- return FormPath.getIn(this.initialValues, pattern)
403
- }
404
-
405
- @action
406
- setLoading = (loading: boolean) => {
407
- setLoading(this, loading)
408
- }
409
-
410
- @action
411
- setSubmitting = (submitting: boolean) => {
412
- setSubmitting(this, submitting)
413
- }
414
-
415
- @action
416
- setValidating = (validating: boolean) => {
417
- setValidating(this, validating)
418
- }
419
-
420
- @action
421
- setDisplay = (display: FormDisplayTypes) => {
422
- this.display = display
423
- }
424
-
425
- @action
426
- setPattern = (pattern: FormPatternTypes) => {
427
- this.pattern = pattern
428
- }
429
-
430
- addEffects = (id: any, effects: IFormProps['effects']) => {
431
- if (!this.heart.hasLifeCycles(id)) {
432
- this.heart.addLifeCycles(id, runEffects(this, effects))
433
- }
434
- }
435
-
436
- removeEffects = (id: any) => {
437
- this.heart.removeLifeCycles(id)
438
- }
439
-
440
- setEffects = (effects: IFormProps['effects']) => {
441
- this.heart.setLifeCycles(runEffects(this, effects))
442
- }
443
-
444
- clearErrors = (pattern: FormPathPattern = '*') => {
445
- this.query(pattern).forEach(field => {
446
- if (!isVoidField(field)) {
447
- field.setFeedback({
448
- type: 'error',
449
- messages: [],
450
- })
451
- }
452
- })
453
- }
454
-
455
- clearWarnings = (pattern: FormPathPattern = '*') => {
456
- this.query(pattern).forEach(field => {
457
- if (!isVoidField(field)) {
458
- field.setFeedback({
459
- type: 'warning',
460
- messages: [],
461
- })
462
- }
463
- })
464
- }
465
-
466
- clearSuccesses = (pattern: FormPathPattern = '*') => {
467
- this.query(pattern).forEach(field => {
468
- if (!isVoidField(field)) {
469
- field.setFeedback({
470
- type: 'success',
471
- messages: [],
472
- })
473
- }
474
- })
475
- }
476
-
477
- query = (pattern: FormPathPattern): Query => {
478
- return new Query({
479
- pattern,
480
- base: '',
481
- form: this,
482
- })
483
- }
484
-
485
- queryFeedbacks = (search: ISearchFeedback): IFormFeedback[] => {
486
- return this.query(search.address || search.path || '*').reduce<IFormFeedback[]>((messages, field) => {
487
- if (isVoidField(field)) return messages
488
- return messages.concat(
489
- field
490
- .queryFeedbacks(search)
491
- .map(feedback => ({
492
- ...feedback,
493
- address: field.address.toString(),
494
- path: field.path.toString(),
495
- }))
496
- .filter(feedback => feedback.messages && feedback.messages.length > 0)
497
- )
498
- }, [])
499
- }
500
-
501
- notify = (type: string, payload?: any) => {
502
- this.heart.publish(type, payload ?? this)
503
- }
504
-
505
- subscribe = (subscriber?: HeartSubscriber) => {
506
- return this.heart.subscribe(subscriber)
507
- }
508
-
509
- unsubscribe = (id: number) => {
510
- this.heart.unsubscribe(id)
511
- }
512
-
513
- /**事件钩子**/
514
-
515
- @batch
516
- onInit = () => {
517
- this.initialized = true
518
- this.notify(LifeCycleTypes.ON_FORM_INIT)
519
- }
520
-
521
- @batch
522
- onMount = () => {
523
- this.mounted = true
524
- this.notify(LifeCycleTypes.ON_FORM_MOUNT)
525
- const devTools = (globalThisPolyfill as any)[DEV_TOOLS_HOOK]
526
- if (devTools && !this.props.designable) {
527
- devTools.inject(this.id, this)
528
- }
529
- }
530
-
531
- @batch
532
- onUnmount = () => {
533
- this.notify(LifeCycleTypes.ON_FORM_UNMOUNT)
534
- this.query('*').forEach(field => field.destroy(false))
535
- this.disposers.forEach(dispose => dispose())
536
- this.unmounted = true
537
- this.indexes = {}
538
- this.heart.clear()
539
- const devTools = (globalThisPolyfill as any)[DEV_TOOLS_HOOK]
540
- if (devTools && !this.props.designable) {
541
- devTools.unmount(this.id)
542
- }
543
- }
544
-
545
- @action
546
- setState: IModelSetter<IFormState<ValueType>> = createStateSetter(this)
547
-
548
- getState: IModelGetter<IFormState<ValueType>> = createStateGetter(this)
549
-
550
- setFormState: IModelSetter<IFormState<ValueType>> = createStateSetter(this)
551
-
552
- getFormState: IModelGetter<IFormState<ValueType>> = createStateGetter(this)
553
-
554
- setFieldState: IFieldStateSetter = createBatchStateSetter(this)
555
-
556
- getFieldState: IFieldStateGetter = createBatchStateGetter(this)
557
-
558
- getFormGraph = () => {
559
- return this.graph.getGraph()
560
- }
561
-
562
- setFormGraph = (graph: IFormGraph) => {
563
- this.graph.setGraph(graph)
564
- }
565
-
566
- clearFormGraph = (pattern: FormPathPattern = '*', forceClear = true) => {
567
- this.query(pattern).forEach(field => {
568
- field.destroy(forceClear)
569
- })
570
- }
571
-
572
- @action
573
- validate = (pattern: FormPathPattern = '*') => {
574
- return batchValidate(this, pattern)
575
- }
576
-
577
- @action
578
- submit = <T>(onSubmit?: (values: ValueType) => Promise<T> | void): Promise<T> => {
579
- return batchSubmit(this, onSubmit)
580
- }
581
-
582
- @action
583
- reset = (pattern: FormPathPattern = '*', options?: IFieldResetOptions) => {
584
- return batchReset(this, pattern, options)
585
- }
586
- }
@@ -1,56 +0,0 @@
1
- import { batch } from '@formvk/reactive'
2
- import { each, FormPath } from '@formvk/shared'
3
-
4
- import { isArrayFieldState, isFieldState, isFormState, isObjectFieldState } from '../shared/checkers'
5
- import type { IFormGraph } from '../types'
6
- import type { Form } from './Form'
7
-
8
- export class Graph {
9
- form: Form
10
-
11
- constructor(form: Form) {
12
- this.form = form
13
- }
14
-
15
- getGraph = (): IFormGraph => {
16
- const graph: Record<string, any> = {}
17
- graph[''] = this.form.getState()
18
- each(this.form.fields, (field: any, identifier) => {
19
- graph[identifier] = field.getState()
20
- })
21
- return graph
22
- }
23
-
24
- setGraph = (graph: IFormGraph) => {
25
- batch(() => {
26
- const form = this.form
27
- const createField = (identifier: string, state: any) => {
28
- const address = FormPath.parse(identifier)
29
- const name = address.segments[address.segments.length - 1]
30
- const basePath = address.parent()
31
- if (isFieldState(state)) {
32
- return this.form.createField({ name, basePath })
33
- } else if (isArrayFieldState(state)) {
34
- return this.form.createArrayField({ name, basePath })
35
- } else if (isObjectFieldState(state)) {
36
- return this.form.createObjectField({ name, basePath })
37
- } else {
38
- return this.form.createVoidField({ name, basePath })
39
- }
40
- }
41
-
42
- each(graph, (state, address) => {
43
- if (isFormState(state)) {
44
- form.setState(state)
45
- } else {
46
- const field = form.fields[address]
47
- if (field) {
48
- field.setState(state)
49
- } else {
50
- createField(address, state)?.setState(state)
51
- }
52
- }
53
- })
54
- })
55
- }
56
- }
@@ -1,75 +0,0 @@
1
- import { isArr, isStr, Subscribable } from '@formvk/shared'
2
-
3
- import type { IHeartProps } from '../types'
4
- import { LifeCycle } from './LifeCycle'
5
- export class Heart<Payload = any, Context = any> extends Subscribable {
6
- lifecycles: LifeCycle<Payload>[] = []
7
-
8
- outerLifecycles: Map<any, LifeCycle<Payload>[]> = new Map()
9
-
10
- context!: Context
11
-
12
- constructor({ lifecycles, context }: IHeartProps<Context> = {}) {
13
- super()
14
- this.lifecycles = this.buildLifeCycles(lifecycles || [])
15
- this.context = context as Context
16
- }
17
-
18
- buildLifeCycles = (lifecycles: any[] = []): LifeCycle<Payload>[] => {
19
- return lifecycles.reduce<LifeCycle<Payload>[]>((buf, item) => {
20
- if (item instanceof LifeCycle) {
21
- return buf.concat(item)
22
- } else {
23
- if (isArr(item)) {
24
- return this.buildLifeCycles(item)
25
- } else if (typeof item === 'object') {
26
- this.context = item as Context
27
- return buf
28
- }
29
- return buf
30
- }
31
- }, [])
32
- }
33
-
34
- addLifeCycles = (id: any, lifecycles: LifeCycle[] = []) => {
35
- const observers = this.buildLifeCycles(lifecycles)
36
- if (observers.length) {
37
- this.outerLifecycles.set(id, observers)
38
- }
39
- }
40
-
41
- hasLifeCycles = (id: any) => {
42
- return this.outerLifecycles.has(id)
43
- }
44
-
45
- removeLifeCycles = (id: any) => {
46
- this.outerLifecycles.delete(id)
47
- }
48
-
49
- setLifeCycles = (lifecycles: LifeCycle[] = []) => {
50
- this.lifecycles = this.buildLifeCycles(lifecycles)
51
- }
52
-
53
- publish = <P, C>(type: any, payload?: P, context?: C) => {
54
- if (isStr(type)) {
55
- this.lifecycles.forEach(lifecycle => {
56
- lifecycle.notify(type, payload, context || this.context)
57
- })
58
- this.outerLifecycles.forEach(lifecycles => {
59
- lifecycles.forEach(lifecycle => {
60
- lifecycle.notify(type, payload, context || this.context)
61
- })
62
- })
63
- this.notify({
64
- type,
65
- payload,
66
- })
67
- }
68
- }
69
-
70
- clear = () => {
71
- this.lifecycles = []
72
- this.outerLifecycles.clear()
73
- this.unsubscribe()
74
- }
75
- }