@retailcrm/embed-ui-v1-testing 0.9.29 → 0.9.30-alpha.2

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.
@@ -6,12 +6,19 @@ import type {
6
6
  TypeOf,
7
7
  } from '@retailcrm/embed-ui-v1-types/context'
8
8
 
9
- import { retain } from '@remote-ui/rpc'
9
+ import { release, retain } from '@remote-ui/rpc'
10
10
  import { watch } from 'vue'
11
11
 
12
12
  const keysOf = <T extends object>(o: T): (keyof T)[] => Object.keys(o) as (keyof T)[]
13
13
 
14
- export const createHandler = <S extends ContextSchema>(id: string, getters: FieldGetters<S>) => {
14
+ export type HandlerCleanup = () => void
15
+ export type RegisterHandlerCleanup = (cleanup: HandlerCleanup) => void
16
+
17
+ export const createHandler = <S extends ContextSchema>(
18
+ id: string,
19
+ getters: FieldGetters<S>,
20
+ registerCleanup?: RegisterHandlerCleanup
21
+ ) => {
15
22
  type EventName = keyof EventMap<S>
16
23
  type FieldName = keyof S
17
24
 
@@ -28,6 +35,11 @@ export const createHandler = <S extends ContextSchema>(id: string, getters: Fiel
28
35
 
29
36
  retain(handler)
30
37
 
31
- watch(getters[map[event] as FieldName], handler as (payload: TypeOf<S[FieldName]>) => void)
38
+ const stop = watch(getters[map[event] as FieldName], payload => (handler as (payload: TypeOf<S[FieldName]>) => void)(payload))
39
+
40
+ registerCleanup?.(() => {
41
+ stop()
42
+ release(handler)
43
+ })
32
44
  }
33
45
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@retailcrm/embed-ui-v1-testing",
3
3
  "type": "module",
4
- "version": "0.9.29",
4
+ "version": "0.9.30-alpha.2",
5
5
  "license": "MIT",
6
6
  "author": "RetailDriverLLC <integration@retailcrm.ru>",
7
7
  "repository": {
@@ -18,6 +18,6 @@
18
18
  "vue": "^3.5"
19
19
  },
20
20
  "dependencies": {
21
- "@retailcrm/embed-ui-v1-types": "^0.9.29"
21
+ "@retailcrm/embed-ui-v1-types": "^0.9.30-alpha.2"
22
22
  }
23
23
  }