esp-js-react 8.1.0 → 9.0.0-beta.1

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 (49) hide show
  1. package/.dist/esp-react.esm.js +713 -0
  2. package/.dist/esp-react.esm.js.map +1 -0
  3. package/.dist/esp-react.js +696 -775
  4. package/.dist/esp-react.js.map +1 -1
  5. package/.dist/esp-react.min.js +20 -3
  6. package/.dist/esp-react.min.js.map +1 -1
  7. package/.dist/typings/connectableComponent.d.ts +5 -6
  8. package/.dist/typings/espApp.d.ts +25 -0
  9. package/.dist/typings/espEventBusContextProvider.d.ts +41 -0
  10. package/.dist/typings/espModulesContext.d.ts +3 -0
  11. package/.dist/typings/espStoreContextProvider.d.ts +62 -0
  12. package/.dist/typings/index.d.ts +13 -9
  13. package/.dist/typings/regionView.d.ts +19 -0
  14. package/.dist/typings/useSyncModelWithSelector.d.ts +9 -16
  15. package/README.md +62 -22
  16. package/package.json +53 -45
  17. package/.dist/esp-react.min.js.LICENSE.txt +0 -9
  18. package/.dist/typings/connect.d.ts +0 -8
  19. package/.dist/typings/espModelContextProvider.d.ts +0 -63
  20. package/.dist/typings/espRouterContextProvider.d.ts +0 -54
  21. package/.dist/typings/polimer/polimerModelBuilderExtentsions.d.ts +0 -6
  22. package/.dist/typings/viewBinder.d.ts +0 -13
  23. package/.dist/typings/viewBindingDecorator.d.ts +0 -34
  24. package/.yarnignore +0 -15
  25. package/docs/images/esp-agile-demo.gif +0 -0
  26. package/jest.config.js +0 -19
  27. package/src/connect.tsx +0 -27
  28. package/src/connectableComponent.tsx +0 -99
  29. package/src/espModelContextProvider.tsx +0 -101
  30. package/src/espRouterContextProvider.tsx +0 -97
  31. package/src/index.ts +0 -68
  32. package/src/polimer/polimerModelBuilderExtentsions.ts +0 -36
  33. package/src/useSyncModelWithSelector.ts +0 -223
  34. package/src/viewBinder.tsx +0 -51
  35. package/src/viewBindingDecorator.ts +0 -113
  36. package/tests/connectableComponentTests.tsx +0 -477
  37. package/tests/espModelContextProviderTests.tsx +0 -150
  38. package/tests/espRouterContextProviderTests.tsx +0 -56
  39. package/tests/indexTests.ts +0 -47
  40. package/tests/testApi/asserts.ts +0 -102
  41. package/tests/testApi/routerSpy.ts +0 -24
  42. package/tests/testApi/testApi.tsx +0 -100
  43. package/tests/testApi/testModel.ts +0 -43
  44. package/tests/testApi/useStoreReceivedProps.ts +0 -14
  45. package/tests/testApi/viewFactory.tsx +0 -31
  46. package/tests/useSyncModelWithSelectorTests.tsx +0 -330
  47. package/tests/viewBinderTests.tsx +0 -61
  48. package/tsconfig.json +0 -14
  49. package/webpack.config.js +0 -27
@@ -1,330 +0,0 @@
1
- import 'jest';
2
- import * as React from 'react';
3
- import {act} from 'react';
4
- import {EspModelContextProvider, EspRouterContextProvider, syncModelWithSelectorOptions, useSyncModelWithSelector} from '../src';
5
- import {TestModel, TestModelImmutableState} from './testApi/testModel';
6
- import {viewFactory, ViewMetadata} from './testApi/viewFactory';
7
- import {routerAsserts} from './testApi/asserts';
8
- import {testApi, TestApi} from './testApi/testApi';
9
- import {TestPropStoreContext} from './testApi/useStoreReceivedProps';
10
-
11
- type SelectedObject = { id: string, value: string };
12
-
13
- describe('useSyncModelWithSelector', () => {
14
- let api: TestApi;
15
-
16
- beforeEach(() => {
17
- api = testApi();
18
- });
19
-
20
- describe('Default API case', () => {
21
- const modelId = 'modelId';
22
-
23
- const View = () => {
24
- const valuesObj = useSyncModelWithSelector<TestModelImmutableState, SelectedObject>(
25
- model => {
26
- return {id: model.modelId, value: model.value};
27
- },
28
- );
29
- if (!valuesObj) {
30
- return;
31
- }
32
- return (
33
- <ViewMetadata modelId={valuesObj.id} modelValue={valuesObj.value} />
34
- );
35
- };
36
-
37
- beforeEach(() => {
38
- api.setupModelAndRender(modelId, View);
39
- });
40
-
41
- it('renders immutable model based on modelId found on context', () => {
42
- api.asserts.view
43
- .modelIdIs(modelId)
44
- .valueIs('initial-value');
45
- });
46
-
47
- it('updates are rendered', () => {
48
- act(() => {
49
- api.router.publishEvent(modelId, 'test-event', 'new-value');
50
- });
51
- api.asserts.view
52
- .modelIdIs(modelId)
53
- .valueIs('new-value');
54
- });
55
- });
56
-
57
- describe('modelId can be passed via selector', () => {
58
- const modelId = 'modelId';
59
-
60
- const View = () => {
61
- const values: string[] = useSyncModelWithSelector<TestModelImmutableState, string[]>(
62
- model => [model.modelId, model.value],
63
- syncModelWithSelectorOptions().setModelId(modelId)
64
- );
65
- if (!values) {
66
- return;
67
- }
68
- return (
69
- <ViewMetadata modelId={values[0]} modelValue={values[1]} />
70
- );
71
- };
72
-
73
- beforeEach(() => {
74
- api.setupTestModel(modelId);
75
- api.doRender(View, undefined);
76
- });
77
-
78
- it('renders correct model data', () => {
79
- api.asserts.view
80
- .modelIdIs(modelId)
81
- .valueIs('initial-value');
82
- });
83
- });
84
-
85
- describe('equalityFn is invoked to determine if changed should be propagated', () => {
86
- const modelId = 'modelId';
87
-
88
- const View = () => {
89
- const values = useSyncModelWithSelector<TestModelImmutableState, SelectedObject>(
90
- model => ({id: model.modelId, value: model.value}),
91
- syncModelWithSelectorOptions<SelectedObject>()
92
- .setEqualityFn((a, b) => {
93
- if (!a) {
94
- return false; // first time
95
- }
96
- // delegate to model, set via the test, to see if we're 'equal'
97
- // If this returns true, useSyncModelWithSelector internally assume the last snapshot is the same thus doesn't propagate the last snapshot.
98
- return b.value === 'assume-no-change';
99
- })
100
- );
101
- if (!values) {
102
- return;
103
- }
104
- return (
105
- <ViewMetadata modelId={values.id} modelValue={values.value} />
106
- );
107
- };
108
-
109
- beforeEach(() => {
110
- api.setupModelAndRender(modelId, View);
111
- });
112
-
113
- it('renders initial model data', () => {
114
- api.asserts.view
115
- .modelIdIs(modelId)
116
- .valueIs('initial-value');
117
- });
118
-
119
- it('updates are ignored due to equalityFn', () => {
120
- api.asserts.view
121
- .modelIdIs(modelId)
122
- .valueIs('initial-value');
123
- act(() => {
124
- api.router.publishEvent(modelId, 'test-event', 'assume-no-change');
125
- });
126
- api.asserts.view
127
- .modelIdIs(modelId)
128
- .valueIs('initial-value'); // event data WAS NOT propagated
129
- act(() => {
130
- api.router.publishEvent(modelId, 'test-event', 'do-change');
131
- });
132
- api.asserts.view
133
- .modelIdIs(modelId)
134
- .valueIs('do-change'); // event data WAS propagated
135
- });
136
- });
137
-
138
- describe('selector internal caching is based on modelId', () => {
139
- const modelId1 = 'modelId1';
140
- const modelId2 = 'modelId2';
141
-
142
- const View = (props: {modelId: string}) => {
143
- const values = useSyncModelWithSelector<TestModelImmutableState, SelectedObject>(
144
- model => ({id: model.modelId, value: model.value}),
145
- syncModelWithSelectorOptions().setModelId(props.modelId)
146
- );
147
- if (!values) {
148
- return;
149
- }
150
- return (
151
- <ViewMetadata modelId={values.id} modelValue={values.value} />
152
- );
153
- };
154
-
155
- beforeEach(() => {
156
- api.setupTestModel(modelId1);
157
- api.doRender(View, modelId1);
158
- });
159
-
160
- it('selector subscribed to Router', () => {
161
- routerAsserts(api.router).subscriberCountIs(modelId1, 1);
162
- });
163
-
164
- it('unsubscribes when modelId changes', () => {
165
- api.doReRender(View, undefined);
166
- api.asserts.router.subscriberCountIs(modelId1, 0);
167
- });
168
-
169
- it('resubscribes to new model when modelId changes', () => {
170
- api.asserts.view
171
- .modelIdIs(modelId1)
172
- .valueIs('initial-value');
173
- api.doReRender(View, undefined);
174
- api.asserts.view
175
- .modelIdIsNotInDom()
176
- .valueIsNotInDom();
177
- api.setupTestModel(modelId2);
178
- api.doReRender(View, modelId2);
179
- api.asserts.view
180
- .modelIdIs(modelId2)
181
- .valueIs('initial-value');
182
- act(() => {
183
- api.router.publishEvent(modelId2, 'test-event', 'updated');
184
- });
185
- api.asserts.view
186
- .modelIdIs(modelId2)
187
- .valueIs('updated');
188
- });
189
- });
190
-
191
- describe('non immutable model cases #1 - selector receives then maps model subset', () => {
192
- const modelId = 'modelId';
193
-
194
- const View = () => {
195
- const values: string[] = useSyncModelWithSelector<TestModel, string[]>(
196
- model => {
197
- // here we're expecting to receive a TestModel, not testModelInstance[GetEspPolimerImmutableModelConsts.HandlerFunctionName]()
198
- return [model.state.modelId, model.state.value];
199
- },
200
- syncModelWithSelectorOptions().setTryPreSelectPolimerImmutableModel(false)
201
- );
202
- if (!values) {
203
- return;
204
- }
205
- return (
206
- <ViewMetadata modelId={values[0]} modelValue={values[1]} />
207
- );
208
- };
209
-
210
- beforeEach(() => {
211
- api.setupModelAndRender(modelId, View);
212
- });
213
-
214
- it('selector passes router root model to selector', () => {
215
- api.asserts.view
216
- .modelIdIs(modelId)
217
- .valueIs('initial-value');
218
- });
219
- });
220
-
221
- describe('non immutable model cases - selector maps root model', () => {
222
- const modelId = 'modelId';
223
-
224
- const View = () => {
225
- const model: TestModel = useSyncModelWithSelector<TestModel, TestModel>(
226
- m => m,
227
- syncModelWithSelectorOptions().setTryPreSelectPolimerImmutableModel(false)
228
- );
229
- if (!model) {
230
- return;
231
- }
232
- return (
233
- <ViewMetadata modelId={model.state.modelId} modelValue={model.state.value} />
234
- );
235
- };
236
-
237
- beforeEach(() => {
238
- api.setupModelAndRender(modelId, View);
239
- });
240
-
241
- it('view renders correct data', () => {
242
- api.asserts.view
243
- .modelIdIs(modelId)
244
- .valueIs('initial-value');
245
- });
246
-
247
- it('Updates propagated', () => {
248
- act(() => {
249
- api.router.publishEvent(modelId, 'test-event', 'updated');
250
- });
251
- api.asserts.view
252
- .modelIdIs(modelId)
253
- .valueIs('updated');
254
- });
255
- });
256
-
257
- describe('noop argument edge cases', () => {
258
- const View = viewFactory('View1');
259
-
260
- it('falsey router', () => {
261
- api.doRender((
262
- <TestPropStoreContext.Provider value={api.propStore}>
263
- <EspRouterContextProvider router={undefined}>
264
- <EspModelContextProvider modelId={'some-modelId'}>
265
- <View />,
266
- </EspModelContextProvider>
267
- </EspRouterContextProvider>
268
- </TestPropStoreContext.Provider>
269
- ));
270
- api.asserts.props
271
- .receivedPropCountIs(1)
272
- .propAtIndexHasModelId(0, undefined)
273
- .propAtIndex(0, props => {
274
- expect(props.modelId).not.toBeDefined();
275
- expect(props.value).not.toBeDefined();
276
- });
277
- });
278
-
279
- it('falsey modelId', () => {
280
- api.doRender((
281
- <TestPropStoreContext.Provider value={api.propStore}>
282
- <EspRouterContextProvider router={api.router}>
283
- <EspModelContextProvider modelId={undefined}>
284
- <View />,
285
- </EspModelContextProvider>
286
- </EspRouterContextProvider>
287
- </TestPropStoreContext.Provider>
288
- ));
289
- api.asserts.props
290
- .receivedPropCountIs(1)
291
- .propAtIndexHasModelId(0, undefined)
292
- .propAtIndex(0, props => {
293
- expect(props.modelId).not.toBeDefined();
294
- expect(props.value).not.toBeDefined();
295
- });
296
- });
297
- });
298
-
299
- describe('argument checking', () => {
300
- it('throws if selector incorrect', () => {
301
- expect(() => {
302
- useSyncModelWithSelector(null, syncModelWithSelectorOptions());
303
- }).toThrow(new Error('You must pass a selector function to useSyncModelWithSelector'));
304
- expect(() => {
305
- useSyncModelWithSelector(undefined, syncModelWithSelectorOptions());
306
- }).toThrow(new Error('You must pass a selector function to useSyncModelWithSelector'));
307
- expect(() => {
308
- const x: any = {};
309
- useSyncModelWithSelector(x, syncModelWithSelectorOptions());
310
- }).toThrow(new Error('You must pass a selector function to useSyncModelWithSelector'));
311
- });
312
- it('throws if options incorrect', () => {
313
- expect(() => {
314
- useSyncModelWithSelector((m) => m, null);
315
- }).toThrow(new Error('You must provide options when using useSyncModelWithSelector'));
316
- expect(() => {
317
- useSyncModelWithSelector((m) => m, syncModelWithSelectorOptions().setEqualityFn(null));
318
- }).toThrow(new Error('You must provide an equalityFn when using useSyncModelWithSelector'));
319
- expect(() => {
320
- useSyncModelWithSelector(
321
- (m) => m,
322
- {
323
- modelId: '',
324
- equalityFn: null,
325
- tryPreSelectPolimerImmutableModel: true
326
- });
327
- }).toThrow(new Error('You must provide an equalityFn when using useSyncModelWithSelector'));
328
- });
329
- });
330
- });
@@ -1,61 +0,0 @@
1
- import {
2
- viewBinding,
3
- ViewBinder,
4
- } from '../src';
5
- import {testApi, TestApi} from './testApi/testApi';
6
- import * as React from 'react';
7
- import {viewFactory} from './testApi/viewFactory';
8
-
9
- @viewBinding(viewFactory('ViewBinder1'))
10
- @viewBinding(viewFactory('ViewBinder2'), 'alternative-view-context')
11
- class TestModel {
12
- public value: string;
13
-
14
- constructor() {
15
- this.value = 'initial-value';
16
- }
17
- }
18
-
19
- describe('ViewBinder tests', () => {
20
- let api: TestApi,
21
- testModel1: TestModel;
22
-
23
- beforeEach(() => {
24
- api = testApi();
25
- testModel1 = new TestModel();
26
- api.setupModel('model-id', testModel1);
27
- });
28
-
29
- it('creates view using the view found on decorator', () => {
30
- api.doRender(
31
- (
32
- <ViewBinder model={testModel1} />
33
- ),
34
- 'model-id'
35
- );
36
- api.asserts.view.viewNameElementTextIs('ViewBinder1');
37
- });
38
-
39
- it('creates view using the view found on decorator with specific context', () => {
40
- api.doRender(
41
- (
42
- <ViewBinder model={testModel1} viewContext={'alternative-view-context'} />
43
- ),
44
- 'model-id'
45
- );
46
- api.asserts.view.viewNameElementTextIs('ViewBinder2');
47
- });
48
-
49
- it('arbitrary props are passed down to the child', () => {
50
- api.doRender(
51
- (
52
- <ViewBinder model={testModel1} className={'foo-bar'} />
53
- ),
54
- 'model-id1'
55
- );
56
- api.asserts.props
57
- .propAtIndex(0, props => {
58
- expect(props.className).toBe('foo-bar');
59
- });
60
- });
61
- });
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir" : "./.tsbuild",
5
- "declarationDir": "./.dist/typings"
6
- },
7
- "include": [
8
- "src/**/*"
9
- ],
10
- "exclude": [
11
- "node_modules",
12
- "**/*.spec.ts"
13
- ]
14
- }
package/webpack.config.js DELETED
@@ -1,27 +0,0 @@
1
- // notice_start
2
- /*
3
- * Copyright 2015 Dev Shop Limited
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the 'License');
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an 'AS IS' BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- // notice_end
18
-
19
- const baseConfig = require("../../webpack.config.base");
20
-
21
- module.exports = {
22
- ...baseConfig,
23
- entry: {
24
- 'esp-react': './src/index.ts',
25
- 'esp-react.min': './src/index.ts',
26
- }
27
- };