repluggable-core 1.302.77 → 1.302.79
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/dist/debug/src/API.d.ts +9 -1
- package/dist/debug/src/extensionSlot.d.ts +13 -2
- package/dist/es/src/API.d.ts +9 -1
- package/dist/es/src/API.d.ts.map +1 -1
- package/dist/es/src/IterableWeakMap.d.ts.map +1 -1
- package/dist/es/src/IterableWeakMap.js.map +1 -1
- package/dist/es/src/appHost.d.ts.map +1 -1
- package/dist/es/src/appHost.js +11 -2
- package/dist/es/src/appHost.js.map +1 -1
- package/dist/es/src/extensionSlot.d.ts +13 -2
- package/dist/es/src/extensionSlot.d.ts.map +1 -1
- package/dist/es/src/extensionSlot.js +21 -9
- package/dist/es/src/extensionSlot.js.map +1 -1
- package/dist/es/src/index.d.ts +1 -1
- package/dist/es/src/index.d.ts.map +1 -1
- package/dist/es/src/index.js.map +1 -1
- package/dist/es/src/throttledStore.d.ts.map +1 -1
- package/dist/es/src/throttledStore.js.map +1 -1
- package/dist/es/test/appHost.spec.js +71 -0
- package/dist/es/test/appHost.spec.js.map +1 -1
- package/dist/es/test/createSignalItemsDataStructure.d.ts +16 -0
- package/dist/es/test/createSignalItemsDataStructure.d.ts.map +1 -0
- package/dist/es/test/createSignalItemsDataStructure.js +54 -0
- package/dist/es/test/createSignalItemsDataStructure.js.map +1 -0
- package/dist/es/test/extensionSlot.spec.d.ts +2 -0
- package/dist/es/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/es/test/extensionSlot.spec.js +136 -0
- package/dist/es/test/extensionSlot.spec.js.map +1 -0
- package/dist/es/testKit/index.d.ts +1 -0
- package/dist/es/testKit/index.d.ts.map +1 -1
- package/dist/es/testKit/index.js +1 -0
- package/dist/es/testKit/index.js.map +1 -1
- package/dist/src/API.d.ts +9 -1
- package/dist/src/API.d.ts.map +1 -1
- package/dist/src/IterableWeakMap.d.ts.map +1 -1
- package/dist/src/IterableWeakMap.js.map +1 -1
- package/dist/src/appHost.d.ts.map +1 -1
- package/dist/src/appHost.js +11 -2
- package/dist/src/appHost.js.map +1 -1
- package/dist/src/extensionSlot.d.ts +13 -2
- package/dist/src/extensionSlot.d.ts.map +1 -1
- package/dist/src/extensionSlot.js +21 -9
- package/dist/src/extensionSlot.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/throttledStore.d.ts.map +1 -1
- package/dist/src/throttledStore.js.map +1 -1
- package/dist/test/appHost.spec.js +71 -0
- package/dist/test/appHost.spec.js.map +1 -1
- package/dist/test/createSignalItemsDataStructure.d.ts +16 -0
- package/dist/test/createSignalItemsDataStructure.d.ts.map +1 -0
- package/dist/test/createSignalItemsDataStructure.js +58 -0
- package/dist/test/createSignalItemsDataStructure.js.map +1 -0
- package/dist/test/extensionSlot.spec.d.ts +2 -0
- package/dist/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/test/extensionSlot.spec.js +138 -0
- package/dist/test/extensionSlot.spec.js.map +1 -0
- package/dist/testKit/index.d.ts +1 -0
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/testKit/index.js +3 -1
- package/dist/testKit/index.js.map +1 -1
- package/package.json +3 -2
- package/src/API.ts +12 -4
- package/src/IterableWeakMap.ts +3 -5
- package/src/__internal.ts +1 -1
- package/src/appHost.ts +10 -2
- package/src/extensionSlot.ts +36 -10
- package/src/index.ts +3 -5
- package/src/throttledStore.ts +9 -15
- package/test/appHost.spec.ts +89 -0
- package/test/createSignalItemsDataStructure.ts +65 -0
- package/test/extensionSlot.spec.ts +176 -0
- package/testKit/index.ts +7 -7
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createAppHost, SlotKey } from '../src'
|
|
2
|
+
import { EntryPoint, ExtensionItem, PrivateAppHost, PrivateExtensionSlot, Shell } from '../src/API'
|
|
3
|
+
import { createExtensionSlot } from '../src/extensionSlot'
|
|
4
|
+
import { addMockShell } from '../testKit'
|
|
5
|
+
import { createSignalItemsDataStructure } from './createSignalItemsDataStructure'
|
|
6
|
+
|
|
7
|
+
describe('ExtensionSlot', () => {
|
|
8
|
+
describe('Subscribe', () => {
|
|
9
|
+
it('should be invoked on contribution', () => {
|
|
10
|
+
const slotKey: SlotKey<{}> = {
|
|
11
|
+
name: 'mock_key'
|
|
12
|
+
}
|
|
13
|
+
const host = createAppHost([])
|
|
14
|
+
const shell = addMockShell(host)
|
|
15
|
+
const spy = jest.fn()
|
|
16
|
+
const slot = shell.declareSlot(slotKey) as PrivateExtensionSlot<{}>
|
|
17
|
+
|
|
18
|
+
slot.subscribe(spy)
|
|
19
|
+
|
|
20
|
+
slot.contribute(shell, () => ({}))
|
|
21
|
+
|
|
22
|
+
expect(spy).toBeCalledTimes(1)
|
|
23
|
+
|
|
24
|
+
slot.contribute(shell, () => ({}))
|
|
25
|
+
|
|
26
|
+
expect(spy).toBeCalledTimes(2)
|
|
27
|
+
})
|
|
28
|
+
it('should be invoked once when contribution is during installation phase', () => {
|
|
29
|
+
interface SlotItem {
|
|
30
|
+
name: string
|
|
31
|
+
}
|
|
32
|
+
const slotKey: SlotKey<SlotItem> = {
|
|
33
|
+
name: 'MOCK_SLOT'
|
|
34
|
+
}
|
|
35
|
+
interface MockContributionAPI {
|
|
36
|
+
contributeItem(fromShell: Shell, item: SlotItem): void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ContributionAPI: SlotKey<MockContributionAPI> = {
|
|
40
|
+
name: 'CONTRIBUTION_API'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const spy = jest.fn()
|
|
44
|
+
|
|
45
|
+
const contributionEntryPoint: EntryPoint = {
|
|
46
|
+
name: 'PRIVATE CONTRIBUTION ENTRY POINT',
|
|
47
|
+
declareAPIs() {
|
|
48
|
+
return [ContributionAPI]
|
|
49
|
+
},
|
|
50
|
+
attach(shell) {
|
|
51
|
+
const slot = shell.declareSlot(slotKey) as PrivateExtensionSlot<SlotItem>
|
|
52
|
+
slot.subscribe(spy)
|
|
53
|
+
shell.contributeAPI(ContributionAPI, () => ({
|
|
54
|
+
contributeItem(fromShell, item) {
|
|
55
|
+
shell.getSlot(slotKey).contribute(fromShell, item)
|
|
56
|
+
}
|
|
57
|
+
}))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const API_A: SlotKey<{}> = { name: 'API_A' }
|
|
62
|
+
|
|
63
|
+
const itemContributionEntryPointA: EntryPoint = {
|
|
64
|
+
name: 'ITEM CONTRIBUTION ENTRY POINT A',
|
|
65
|
+
getDependencyAPIs() {
|
|
66
|
+
return [ContributionAPI]
|
|
67
|
+
},
|
|
68
|
+
declareAPIs(): SlotKey<{}>[] {
|
|
69
|
+
return [API_A]
|
|
70
|
+
},
|
|
71
|
+
attach(shell: Shell) {
|
|
72
|
+
shell.contributeAPI(API_A, () => ({}))
|
|
73
|
+
},
|
|
74
|
+
extend(shell: Shell) {
|
|
75
|
+
shell.getAPI(ContributionAPI).contributeItem(shell, { name: 'A.1' })
|
|
76
|
+
shell.getAPI(ContributionAPI).contributeItem(shell, { name: 'A.2' })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const itemContributionEntryPointB: EntryPoint = {
|
|
81
|
+
name: 'ITEM CONTRIBUTION ENTRY POINT B',
|
|
82
|
+
getDependencyAPIs() {
|
|
83
|
+
return [ContributionAPI, API_A]
|
|
84
|
+
},
|
|
85
|
+
extend(shell: Shell) {
|
|
86
|
+
shell.getAPI(ContributionAPI).contributeItem(shell, { name: 'B.1' })
|
|
87
|
+
shell.getAPI(ContributionAPI).contributeItem(shell, { name: 'B.2' })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
createAppHost([contributionEntryPoint, itemContributionEntryPointA, itemContributionEntryPointB])
|
|
92
|
+
|
|
93
|
+
expect(spy).toBeCalledTimes(1)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('Custom Items Data Structure with Signals', () => {
|
|
98
|
+
it('should notify effect when items are added', () => {
|
|
99
|
+
const slotKey: SlotKey<{ value: string }> = { name: 'signal_slot' }
|
|
100
|
+
const host = createAppHost([]) as PrivateAppHost
|
|
101
|
+
const shell = addMockShell(host)
|
|
102
|
+
|
|
103
|
+
const { createDataStructure: dataStructure, getSignalToTrack, effect } = createSignalItemsDataStructure()
|
|
104
|
+
const effectSpy = jest.fn()
|
|
105
|
+
|
|
106
|
+
const slot = createExtensionSlot(slotKey, host, {
|
|
107
|
+
customCreateExtensionSlot: dataStructure
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
effect(() => {
|
|
111
|
+
getSignalToTrack().get()
|
|
112
|
+
effectSpy()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
expect(effectSpy).toHaveBeenCalledTimes(1)
|
|
116
|
+
|
|
117
|
+
slot.contribute(shell, { value: 'item1' })
|
|
118
|
+
expect(effectSpy).toHaveBeenCalledTimes(2)
|
|
119
|
+
|
|
120
|
+
slot.contribute(shell, { value: 'item2' })
|
|
121
|
+
expect(effectSpy).toHaveBeenCalledTimes(3)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('should notify effect when items are filtered/removed', () => {
|
|
125
|
+
const slotKey: SlotKey<{ id: number }> = { name: 'filter_signal_slot' }
|
|
126
|
+
const host = createAppHost([]) as PrivateAppHost
|
|
127
|
+
const shell = addMockShell(host)
|
|
128
|
+
|
|
129
|
+
const { createDataStructure: dataStructure, getSignalToTrack, effect } = createSignalItemsDataStructure()
|
|
130
|
+
const effectSpy = jest.fn()
|
|
131
|
+
|
|
132
|
+
const slot = createExtensionSlot(slotKey, host, {
|
|
133
|
+
customCreateExtensionSlot: dataStructure
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
effect(() => {
|
|
137
|
+
getSignalToTrack().get()
|
|
138
|
+
effectSpy()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
expect(effectSpy).toHaveBeenCalledTimes(1)
|
|
142
|
+
|
|
143
|
+
slot.contribute(shell, { id: 1 })
|
|
144
|
+
slot.contribute(shell, { id: 2 })
|
|
145
|
+
expect(effectSpy).toHaveBeenCalledTimes(3)
|
|
146
|
+
|
|
147
|
+
slot.discardBy((item: ExtensionItem<{ id: number }>) => item.contribution.id === 1)
|
|
148
|
+
expect(effectSpy).toHaveBeenCalledTimes(4)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('should track signal value correctly', () => {
|
|
152
|
+
const slotKey: SlotKey<{ name: string }> = { name: 'track_slot' }
|
|
153
|
+
const host = createAppHost([]) as PrivateAppHost
|
|
154
|
+
const shell = addMockShell(host)
|
|
155
|
+
|
|
156
|
+
const { createDataStructure: dataStructure, getSignalToTrack, effect } = createSignalItemsDataStructure()
|
|
157
|
+
let capturedItems: ExtensionItem<{ name: string }>[] = []
|
|
158
|
+
|
|
159
|
+
const slot = createExtensionSlot(slotKey, host, {
|
|
160
|
+
customCreateExtensionSlot: dataStructure
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
effect(() => {
|
|
164
|
+
capturedItems = getSignalToTrack().get()
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
slot.contribute(shell, { name: 'first' })
|
|
168
|
+
expect(capturedItems).toHaveLength(1)
|
|
169
|
+
expect(capturedItems[0].contribution.name).toBe('first')
|
|
170
|
+
|
|
171
|
+
slot.contribute(shell, { name: 'second' })
|
|
172
|
+
expect(capturedItems).toHaveLength(2)
|
|
173
|
+
expect(capturedItems[1].contribution.name).toBe('second')
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
})
|
package/testKit/index.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { AnySlotKey, AppHost, createAppHost as _createAppHost, EntryPointOrPacka
|
|
|
4
4
|
import { createShellLogger } from '../src/loggers'
|
|
5
5
|
import { emptyLoggerOptions } from './emptyLoggerOptions'
|
|
6
6
|
|
|
7
|
-
export {createShellLogger}
|
|
7
|
+
export { createShellLogger }
|
|
8
8
|
export { emptyLoggerOptions }
|
|
9
9
|
export { AppHost } from '../src/index'
|
|
10
10
|
|
|
11
11
|
export { withConsoleErrors } from './withConsoleErrors'
|
|
12
12
|
export { withThrowOnError } from './withThrowOnError'
|
|
13
13
|
export * from './mockPackage'
|
|
14
|
+
export { createSignalItemsDataStructure } from '../test/createSignalItemsDataStructure'
|
|
14
15
|
|
|
15
16
|
export const createAppHost: typeof _createAppHost = (packages, options = emptyLoggerOptions) => {
|
|
16
17
|
return _createAppHost(packages, options)
|
|
@@ -74,7 +75,10 @@ export function createAppHostWithPacts(packages: EntryPointOrPackage[], pacts: P
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
return createAppHost([...packages, pactsEntryPoint], {
|
|
78
|
+
return createAppHost([...packages, pactsEntryPoint], {
|
|
79
|
+
...emptyLoggerOptions,
|
|
80
|
+
disableLayersValidation: true
|
|
81
|
+
})
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
export async function createAppHostAndWaitForLoading(packages: EntryPointOrPackage[], pacts: PactAPIBase[]): Promise<AppHost> {
|
|
@@ -88,7 +92,7 @@ export async function createAppHostAndWaitForLoading(packages: EntryPointOrPacka
|
|
|
88
92
|
setTimeout(() => {
|
|
89
93
|
const readyAPIs = Array.from(globalThis.repluggableAppDebug.readyAPIs)
|
|
90
94
|
const unreadyAPIs = declaredAPIs.filter(api => !readyAPIs.some(readyAPI => readyAPI.name === api.name))
|
|
91
|
-
const rootUnreadyAPI = globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
|
|
95
|
+
const rootUnreadyAPI = globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
|
|
92
96
|
|
|
93
97
|
reject(
|
|
94
98
|
new Error(
|
|
@@ -118,7 +122,6 @@ in addition here's the full list of declared APIs that have not been contributed
|
|
|
118
122
|
return Promise.race([timeoutPromise, loadingPromise]).then(() => appHost)
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
|
|
122
125
|
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
|
123
126
|
interface EntryPointOverrides extends Omit<EntryPoint, 'name'> {
|
|
124
127
|
name?: EntryPoint['name']
|
|
@@ -159,8 +162,6 @@ export const addMockShell = (host: AppHost, entryPointOverrides: EntryPointOverr
|
|
|
159
162
|
return shell
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
|
|
163
|
-
|
|
164
165
|
export function mockObservable<T>(value: T): ObservableState<T> {
|
|
165
166
|
return {
|
|
166
167
|
subscribe: () => {
|
|
@@ -171,4 +172,3 @@ export function mockObservable<T>(value: T): ObservableState<T> {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
|
-
|