esp-js-react 7.0.2 → 8.0.0-next.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.
- package/.dist/esp-react.js +425 -510
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +2 -1
- package/.dist/esp-react.min.js.LICENSE.txt +9 -0
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/connect.d.ts +12 -0
- package/.dist/typings/connectableComponent.d.ts +20 -46
- package/.dist/typings/espModelContext.d.ts +7 -8
- package/.dist/typings/espRouterContext.d.ts +47 -0
- package/.dist/typings/index.d.ts +7 -6
- package/.dist/typings/{getEspReactRenderModel.d.ts → polimer/getEspReactRenderModel.d.ts} +7 -0
- package/.dist/typings/useModelSelector.d.ts +13 -0
- package/.dist/typings/viewBinder.d.ts +1 -8
- package/.dist/typings/viewBinderConnectable.d.ts +15 -0
- package/.dist/typings/viewBindingDecorator.d.ts +1 -2
- package/package.json +7 -6
- package/src/connect.tsx +31 -0
- package/src/connectableComponent.tsx +93 -190
- package/src/espModelContext.tsx +49 -23
- package/src/espRouterContext.tsx +88 -0
- package/src/index.ts +32 -16
- package/src/polimer/getEspReactRenderModel.ts +50 -0
- package/src/useModelSelector.ts +94 -0
- package/src/viewBinder.tsx +14 -22
- package/src/viewBinderConnectable.tsx +53 -0
- package/src/viewBindingDecorator.ts +2 -3
- package/tests/connectWithSelectorTests.tsx +67 -0
- package/tests/connectableComponentLegacyTests.tsx +405 -0
- package/tests/indexTests.ts +0 -12
- package/.dist/typings/routerProvider.d.ts +0 -18
- package/.dist/typings/shallowEqual.d.ts +0 -21
- package/.dist/typings/shouldUpdateMixin.d.ts +0 -10
- package/.dist/typings/smartComponent.d.ts +0 -33
- package/.dist/typings/utils.d.ts +0 -5
- package/src/getEspReactRenderModel.ts +0 -27
- package/src/routerProvider.tsx +0 -47
- package/src/shallowEqual.ts +0 -70
- package/src/shouldUpdateMixin.ts +0 -73
- package/src/smartComponent.tsx +0 -93
- package/src/utils.ts +0 -61
- package/tests/connectableComponentTests.tsx +0 -390
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import 'jest';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
connect,
|
|
5
|
+
ConnectableComponent,
|
|
6
|
+
ConnectableComponentProps,
|
|
7
|
+
viewBinding,
|
|
8
|
+
getEspReactRenderModel,
|
|
9
|
+
PublishModelEventDelegate,
|
|
10
|
+
RouterContext,
|
|
11
|
+
EspRouterContext
|
|
12
|
+
} from '../src';
|
|
13
|
+
import {Router, observeEvent, utils} from 'esp-js';
|
|
14
|
+
import {render, RenderResult} from '@testing-library/react';
|
|
15
|
+
|
|
16
|
+
const getPropsAsDataAttributesWithMetadata = (props: any) => {
|
|
17
|
+
const propsAsDataAttributes: {[key: string]: string} = Object.keys(props).reduce((result: any, key: string) => {
|
|
18
|
+
let prop = props[key];
|
|
19
|
+
// need to lower case data-* attributes else React throws a warning
|
|
20
|
+
result[`data-${key.toLowerCase()}`] = utils.isString(prop)
|
|
21
|
+
? prop
|
|
22
|
+
: typeof prop;
|
|
23
|
+
return result;
|
|
24
|
+
}, {});
|
|
25
|
+
return propsAsDataAttributes;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class TestModelView1 extends React.Component {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
render() {
|
|
34
|
+
return <div>
|
|
35
|
+
<span data-testid='span-with-props-as-attributes' {...getPropsAsDataAttributesWithMetadata(this.props)} />
|
|
36
|
+
<span data-testid='view-text'>View1</span>
|
|
37
|
+
</div>;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class TestModelView2 extends React.Component {
|
|
42
|
+
constructor(props) {
|
|
43
|
+
super(props);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
return <div>
|
|
48
|
+
<span data-testid='span-with-props-as-attributes' {...getPropsAsDataAttributesWithMetadata(this.props)} />
|
|
49
|
+
<span data-testid='view-text'>View2</span>
|
|
50
|
+
</div>;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class TestModelView3 extends React.Component {
|
|
55
|
+
constructor(props) {
|
|
56
|
+
super(props);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
return <span>View3</span>;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@viewBinding(TestModelView1)
|
|
65
|
+
@viewBinding(TestModelView3, 'alternative-view-context')
|
|
66
|
+
class TestModel {
|
|
67
|
+
public value: string;
|
|
68
|
+
|
|
69
|
+
constructor() {
|
|
70
|
+
this.value = 'initial-value';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@observeEvent('test-event')
|
|
74
|
+
_onTestEvent(ev) {
|
|
75
|
+
this.value = ev;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class TestModel2 extends TestModel {
|
|
80
|
+
@getEspReactRenderModel()
|
|
81
|
+
_getOtherState() {
|
|
82
|
+
return {
|
|
83
|
+
value: this.value,
|
|
84
|
+
value2: this.value,
|
|
85
|
+
value3: 'value-3'
|
|
86
|
+
} as MappedModel;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class TestModel3 extends TestModel {
|
|
91
|
+
getEspReactRenderModel() {
|
|
92
|
+
return {
|
|
93
|
+
value: this.value,
|
|
94
|
+
value2: this.value,
|
|
95
|
+
value3: 'value-3.1'
|
|
96
|
+
} as MappedModel;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface MappedModel {
|
|
101
|
+
value: string;
|
|
102
|
+
value2: string;
|
|
103
|
+
value3: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface TestOptions {
|
|
107
|
+
useConnectFunction?: boolean;
|
|
108
|
+
useMapModelToProps?: boolean;
|
|
109
|
+
useCreatePublishEventProps?: boolean;
|
|
110
|
+
useAlternativeViewContext?: boolean;
|
|
111
|
+
passOtherProps?: boolean;
|
|
112
|
+
useRenderModelSelectorDecorator?: boolean;
|
|
113
|
+
useRenderModelSelectorFunction?: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe('ConnectableComponent', () => {
|
|
117
|
+
let router,
|
|
118
|
+
testModel: TestModel,
|
|
119
|
+
testModel2: TestModel,
|
|
120
|
+
renderResult: RenderResult,
|
|
121
|
+
connectableComponentProps: ConnectableComponentProps<TestModel>,
|
|
122
|
+
mapModelToProps,
|
|
123
|
+
createPublishEventProps,
|
|
124
|
+
publishEventProps,
|
|
125
|
+
userAlternativeViewContext,
|
|
126
|
+
otherProps = {other1: 'other-value'};
|
|
127
|
+
|
|
128
|
+
function createModel(options: TestOptions) {
|
|
129
|
+
if (options.useRenderModelSelectorDecorator) {
|
|
130
|
+
return new TestModel2();
|
|
131
|
+
}
|
|
132
|
+
if (options.useRenderModelSelectorFunction) {
|
|
133
|
+
return new TestModel3();
|
|
134
|
+
}
|
|
135
|
+
return new TestModel();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function setup(options: TestOptions) {
|
|
139
|
+
router = new Router();
|
|
140
|
+
testModel = createModel(options);
|
|
141
|
+
router.addModel('model-id', testModel);
|
|
142
|
+
router.observeEventsOn('model-id', testModel);
|
|
143
|
+
testModel2 = new TestModel();
|
|
144
|
+
router.addModel('model-id2', testModel2);
|
|
145
|
+
router.observeEventsOn('model-id2', testModel2);
|
|
146
|
+
connectableComponentProps = {
|
|
147
|
+
modelId: 'model-id'
|
|
148
|
+
};
|
|
149
|
+
if (options.useMapModelToProps) {
|
|
150
|
+
mapModelToProps = (model: TestModel | MappedModel, publishEventProps2: any) => {
|
|
151
|
+
return {
|
|
152
|
+
foo: model.value,
|
|
153
|
+
publishEventProps: publishEventProps2,
|
|
154
|
+
...model
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (options.useCreatePublishEventProps) {
|
|
159
|
+
publishEventProps = {
|
|
160
|
+
publishEvent1: () => {
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
createPublishEventProps = (publishEvent: PublishModelEventDelegate) => publishEventProps;
|
|
164
|
+
}
|
|
165
|
+
if (options.useAlternativeViewContext) {
|
|
166
|
+
userAlternativeViewContext = 'alternative-view-context';
|
|
167
|
+
}
|
|
168
|
+
if (options.useConnectFunction) {
|
|
169
|
+
const TestModelView2ConnectedComponent = connect(
|
|
170
|
+
mapModelToProps,
|
|
171
|
+
createPublishEventProps
|
|
172
|
+
)(TestModelView2);
|
|
173
|
+
renderResult = render(
|
|
174
|
+
<RouterContext.Provider value={router} >
|
|
175
|
+
<TestModelView2ConnectedComponent {...otherProps} {...connectableComponentProps}/>,
|
|
176
|
+
</RouterContext.Provider>
|
|
177
|
+
);
|
|
178
|
+
} else {
|
|
179
|
+
renderResult = render(
|
|
180
|
+
<EspRouterContext router={router} >
|
|
181
|
+
<ConnectableComponent
|
|
182
|
+
{...connectableComponentProps}
|
|
183
|
+
mapModelToProps={mapModelToProps}
|
|
184
|
+
viewContext={userAlternativeViewContext}
|
|
185
|
+
{...otherProps}
|
|
186
|
+
/>
|
|
187
|
+
</EspRouterContext>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function publishAnEventToModel1() {
|
|
193
|
+
router.publishEvent('model-id', 'test-event', 'the-event-value');
|
|
194
|
+
expect(testModel.value).toEqual('the-event-value');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function publishAnEventToModel2() {
|
|
198
|
+
router.publishEvent('model-id2', 'test-event', 'the-event-value2');
|
|
199
|
+
expect(testModel2.value).toEqual('the-event-value2');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
afterEach(() => {
|
|
203
|
+
// console.log(connectableComponentWrapper.debug());
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('ConnectableComponent via connect()', () => {
|
|
207
|
+
beforeEach(() => {
|
|
208
|
+
setup({useConnectFunction: true, useMapModelToProps: true, useCreatePublishEventProps: true});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const getSpanWithPropsAsAttributes = () => {
|
|
212
|
+
return renderResult.getByTestId('span-with-props-as-attributes');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
describe('Child view props', () => {
|
|
216
|
+
it('passes mapped props', () => {
|
|
217
|
+
let span = getSpanWithPropsAsAttributes();
|
|
218
|
+
expect(span.getAttribute('data-foo')).toBe('initial-value');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// it('passes publishEventProps to props mapper', () => {
|
|
222
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
223
|
+
// expect(span.getAttribute('publishEventProps')).toBe('function');
|
|
224
|
+
// });
|
|
225
|
+
//
|
|
226
|
+
// it('passes model', () => {
|
|
227
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
228
|
+
// expect(props.model).toBe(testModel);
|
|
229
|
+
// });
|
|
230
|
+
//
|
|
231
|
+
// it('passes publishEventProps', () => {
|
|
232
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
233
|
+
// expect(props.publishEvent1).toBeDefined();
|
|
234
|
+
// });
|
|
235
|
+
//
|
|
236
|
+
// it('passes other props', () => {
|
|
237
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
238
|
+
// expect(props.other1).toEqual('other-value');
|
|
239
|
+
// });
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// describe('View rendering', () => {
|
|
243
|
+
// it('Renders the view provided to connect', () => {
|
|
244
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView2/>)).toBeTruthy();
|
|
245
|
+
// });
|
|
246
|
+
// });
|
|
247
|
+
});
|
|
248
|
+
//
|
|
249
|
+
// describe('ConnectableComponent directly', () => {
|
|
250
|
+
//
|
|
251
|
+
// const getSpanWithPropsAsAttributes = () => {
|
|
252
|
+
// return connectableComponentWrapper.childAt(0).props() as ConnectableComponentChildProps<TestModel>;
|
|
253
|
+
// };
|
|
254
|
+
//
|
|
255
|
+
// describe('Child view props', () => {
|
|
256
|
+
// beforeEach(() => {
|
|
257
|
+
// setup({useConnectFunction: false});
|
|
258
|
+
// });
|
|
259
|
+
//
|
|
260
|
+
// it('passes modelId', () => {
|
|
261
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
262
|
+
// expect(props.modelId).toEqual('model-id');
|
|
263
|
+
// });
|
|
264
|
+
//
|
|
265
|
+
// it('passes router', () => {
|
|
266
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
267
|
+
// expect(props.router).toBe(router);
|
|
268
|
+
// });
|
|
269
|
+
//
|
|
270
|
+
// it('passes model', () => {
|
|
271
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
272
|
+
// expect(props.model).toBe(testModel);
|
|
273
|
+
// });
|
|
274
|
+
//
|
|
275
|
+
// it('passes other props', () => {
|
|
276
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
277
|
+
// expect(props.other1).toEqual('other-value');
|
|
278
|
+
// });
|
|
279
|
+
// });
|
|
280
|
+
//
|
|
281
|
+
// describe('Re-renders', () => {
|
|
282
|
+
// beforeEach(() => {
|
|
283
|
+
// setup({useConnectFunction: false});
|
|
284
|
+
// });
|
|
285
|
+
//
|
|
286
|
+
// it('Re-renders when model updates', () => {
|
|
287
|
+
// publishAnEventToModel1();
|
|
288
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
289
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
290
|
+
// });
|
|
291
|
+
// });
|
|
292
|
+
//
|
|
293
|
+
// describe('Model Subscription', () => {
|
|
294
|
+
// beforeEach(() => {
|
|
295
|
+
// setup({useConnectFunction: false});
|
|
296
|
+
// });
|
|
297
|
+
//
|
|
298
|
+
// it('Re-subscribes to new model when modelId changes', () => {
|
|
299
|
+
// const newProps = {
|
|
300
|
+
// ...connectableComponentWrapper.props(),
|
|
301
|
+
// modelId: 'model-id2',
|
|
302
|
+
// };
|
|
303
|
+
// connectableComponentWrapper.setProps(newProps);
|
|
304
|
+
// publishAnEventToModel2();
|
|
305
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
306
|
+
// expect(props.foo).toBe('the-event-value2');
|
|
307
|
+
// });
|
|
308
|
+
// });
|
|
309
|
+
//
|
|
310
|
+
// describe('Publish Event Context', () => {
|
|
311
|
+
// beforeEach(() => {
|
|
312
|
+
// setup({useConnectFunction: false});
|
|
313
|
+
// });
|
|
314
|
+
//
|
|
315
|
+
// // Cant test hooks yet, will test using state below
|
|
316
|
+
// // https://github.com/enzymejs/enzyme/issues/2011
|
|
317
|
+
// xit('Can publish event via context', () => {
|
|
318
|
+
// const childViewContext = connectableComponentWrapper.context();
|
|
319
|
+
// let publishEvent: PublishModelEventDelegate = React.useContext(PublishModelEventContext);
|
|
320
|
+
// publishEvent('test-event', 'the-event-value');
|
|
321
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
322
|
+
// expect(props.foo).toBe('the-event-value');
|
|
323
|
+
// });
|
|
324
|
+
//
|
|
325
|
+
// // Note this is a a best effort to test the context hook created via state
|
|
326
|
+
// it('publishEvent set', () => {
|
|
327
|
+
// const state = connectableComponentWrapper.state();
|
|
328
|
+
// state.publishEvent('test-event', 'the-event-value');
|
|
329
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
330
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
331
|
+
// });
|
|
332
|
+
//
|
|
333
|
+
// it('publishEvent recreated on modle change', () => {
|
|
334
|
+
// const newProps = {
|
|
335
|
+
// ...connectableComponentWrapper.props(),
|
|
336
|
+
// modelId: 'model-id2',
|
|
337
|
+
// };
|
|
338
|
+
// connectableComponentWrapper.setProps(newProps);
|
|
339
|
+
// const state = connectableComponentWrapper.state();
|
|
340
|
+
// state.publishEvent('test-event', 'the-event-value');
|
|
341
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
342
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
343
|
+
// expect(testModel2.value).toBe('the-event-value');
|
|
344
|
+
// });
|
|
345
|
+
// });
|
|
346
|
+
//
|
|
347
|
+
// describe('View rendering', () => {
|
|
348
|
+
// it('Renders the view found via @viewBinding', () => {
|
|
349
|
+
// setup({useConnectFunction: false});
|
|
350
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView1/>)).toBeTruthy();
|
|
351
|
+
// });
|
|
352
|
+
//
|
|
353
|
+
// it('Renders alternative view found via @viewBinding', () => {
|
|
354
|
+
// setup({useConnectFunction: false, useAlternativeViewContext: true});
|
|
355
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView3/>)).toBeTruthy();
|
|
356
|
+
// });
|
|
357
|
+
// });
|
|
358
|
+
//
|
|
359
|
+
// describe('Overriding model/state selector', () => {
|
|
360
|
+
// function testModelHasBeenReplacedWithMappedModel(expectedValue3) {
|
|
361
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
362
|
+
// let mappedModel = props.model as any as MappedModel;
|
|
363
|
+
// expect(mappedModel.value2).toBe('initial-value');
|
|
364
|
+
// expect(mappedModel.value3).toBe(expectedValue3);
|
|
365
|
+
// publishAnEventToModel1();
|
|
366
|
+
// props = getSpanWithPropsAsAttributes();
|
|
367
|
+
// mappedModel = props.model as any as MappedModel;
|
|
368
|
+
// expect(mappedModel.value2).toBe('the-event-value');
|
|
369
|
+
// }
|
|
370
|
+
//
|
|
371
|
+
// function testSwappedModelPassedToMapModelToPropsFunction(expectedValue3) {
|
|
372
|
+
// let props = getSpanWithPropsAsAttributes();
|
|
373
|
+
// expect(props.value2).toBe('initial-value');
|
|
374
|
+
// expect(props.value3).toBe(expectedValue3);
|
|
375
|
+
// publishAnEventToModel1();
|
|
376
|
+
// props = getSpanWithPropsAsAttributes();
|
|
377
|
+
// expect(props.value2).toBe('the-event-value');
|
|
378
|
+
// }
|
|
379
|
+
//
|
|
380
|
+
// describe('using @stateToRenderSelector', () => {
|
|
381
|
+
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
382
|
+
// setup({useConnectFunction: false, useRenderModelSelectorDecorator: true});
|
|
383
|
+
// testModelHasBeenReplacedWithMappedModel('value-3');
|
|
384
|
+
// });
|
|
385
|
+
//
|
|
386
|
+
// it('passes the swapped model to mapModelToProps function', () => {
|
|
387
|
+
// setup({useConnectFunction: false, useRenderModelSelectorDecorator: true, useMapModelToProps: true});
|
|
388
|
+
// testSwappedModelPassedToMapModelToPropsFunction('value-3');
|
|
389
|
+
// });
|
|
390
|
+
// });
|
|
391
|
+
//
|
|
392
|
+
// describe('using state to render function', () => {
|
|
393
|
+
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
394
|
+
// setup({useConnectFunction: false, useRenderModelSelectorFunction: true});
|
|
395
|
+
// testModelHasBeenReplacedWithMappedModel('value-3.1');
|
|
396
|
+
// });
|
|
397
|
+
//
|
|
398
|
+
// it('passes the swapped model to mapModelToProps function', () => {
|
|
399
|
+
// setup({useConnectFunction: false, useRenderModelSelectorFunction: true, useMapModelToProps: true});
|
|
400
|
+
// testSwappedModelPassedToMapModelToPropsFunction('value-3.1');
|
|
401
|
+
// });
|
|
402
|
+
// });
|
|
403
|
+
// });
|
|
404
|
+
// });
|
|
405
|
+
});
|
package/tests/indexTests.ts
CHANGED
|
@@ -18,12 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
import * as espReact from '../src/index';
|
|
20
20
|
import {
|
|
21
|
-
SmartComponent,
|
|
22
21
|
ViewBinder,
|
|
23
22
|
viewBinding,
|
|
24
23
|
getEspReactRenderModel,
|
|
25
24
|
GetEspReactRenderModelConsts,
|
|
26
|
-
shouldUpdateMixin,
|
|
27
25
|
|
|
28
26
|
useRouter,
|
|
29
27
|
RouterContext,
|
|
@@ -53,11 +51,6 @@ describe('index exports', () => {
|
|
|
53
51
|
expect(RouterContext).toBeDefined();
|
|
54
52
|
});
|
|
55
53
|
|
|
56
|
-
it('should export SmartComponent', () => {
|
|
57
|
-
expect(espReact.SmartComponent).toBeDefined();
|
|
58
|
-
expect(SmartComponent).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
54
|
it('should export ViewBinder', () => {
|
|
62
55
|
expect(espReact.ViewBinder).toBeDefined();
|
|
63
56
|
expect(ViewBinder).toBeDefined();
|
|
@@ -78,11 +71,6 @@ describe('index exports', () => {
|
|
|
78
71
|
expect(GetEspReactRenderModelConsts).toBeDefined();
|
|
79
72
|
});
|
|
80
73
|
|
|
81
|
-
it('should export shouldUpdateMixin', () => {
|
|
82
|
-
expect(espReact.shouldUpdateMixin).toBeDefined();
|
|
83
|
-
expect(shouldUpdateMixin).toBeDefined();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
74
|
describe('hooks', () => {
|
|
87
75
|
|
|
88
76
|
it('should export useRouter and related', () => {
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
|
-
import { Router } from 'esp-js';
|
|
4
|
-
export interface RouterProviderProps {
|
|
5
|
-
router: Router;
|
|
6
|
-
children: any;
|
|
7
|
-
}
|
|
8
|
-
export declare const RouterContext: React.Context<Router>;
|
|
9
|
-
export declare const useRouter: () => Router;
|
|
10
|
-
export declare class RouterProvider extends React.Component<RouterProviderProps, any> {
|
|
11
|
-
static childContextTypes: {
|
|
12
|
-
router: PropTypes.Validator<Router>;
|
|
13
|
-
};
|
|
14
|
-
getChildContext(): {
|
|
15
|
-
router: Router;
|
|
16
|
-
};
|
|
17
|
-
render(): React.JSX.Element;
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @providesModule shallowEqual
|
|
8
|
-
* @typechecks
|
|
9
|
-
* @flow
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
13
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
14
|
-
*/
|
|
15
|
-
export declare function is(x: any, y: any): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Performs equality by iterating through keys on an object and returning false
|
|
18
|
-
* when any key has values which are not strictly equal between the arguments.
|
|
19
|
-
* Returns true when the values of all keys are strictly equal.
|
|
20
|
-
*/
|
|
21
|
-
export declare function shallowEqual(objA: any, objB: any): boolean;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export declare function shouldUpdateMixin<TProps, TState, TPropBindings>(itemsThatEffectUpdateSelector: (nextProps: TProps) => TPropBindings): <TConstructor extends {
|
|
3
|
-
new (...args: any[]): {};
|
|
4
|
-
}>(Constructor: TConstructor) => {
|
|
5
|
-
new (...args: any[]): {
|
|
6
|
-
_propBindings: {};
|
|
7
|
-
shouldComponentUpdate(nextProps: any, nextState: any): boolean;
|
|
8
|
-
render(): React.CElement<any, React.Component<any, any, any>>;
|
|
9
|
-
};
|
|
10
|
-
} & TConstructor;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
|
-
import { Router } from 'esp-js';
|
|
4
|
-
export interface SmartComponentProps {
|
|
5
|
-
modelId: string;
|
|
6
|
-
view?: any;
|
|
7
|
-
viewContext?: string;
|
|
8
|
-
modelSelector?: (model: any) => any;
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}
|
|
11
|
-
export interface SmartComponentState {
|
|
12
|
-
model: any;
|
|
13
|
-
}
|
|
14
|
-
export declare class SmartComponent extends React.Component<SmartComponentProps, SmartComponentState> {
|
|
15
|
-
private _currentObservingModelId;
|
|
16
|
-
private _observationSubscription;
|
|
17
|
-
static contextTypes: {
|
|
18
|
-
router: PropTypes.Validator<Router>;
|
|
19
|
-
};
|
|
20
|
-
componentWillReceiveProps(nextProps: SmartComponentProps): void;
|
|
21
|
-
componentWillMount(): void;
|
|
22
|
-
componentWillUnmount(): void;
|
|
23
|
-
_tryObserveModel(modelId: any): void;
|
|
24
|
-
_tryDisposeObservationSubscription(): void;
|
|
25
|
-
render(): React.CElement<any, React.Component<any, any, any>>;
|
|
26
|
-
_getChildProps(): {
|
|
27
|
-
model: any;
|
|
28
|
-
router: any;
|
|
29
|
-
} & {
|
|
30
|
-
readonly [x: string]: any;
|
|
31
|
-
children?: React.ReactNode | undefined;
|
|
32
|
-
};
|
|
33
|
-
}
|
package/.dist/typings/utils.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function removeAll(arr: any, item: any): void;
|
|
2
|
-
export declare function isString(value: any): value is string | String;
|
|
3
|
-
export declare function format(formatString: any): any;
|
|
4
|
-
export declare function startsWith(string: any, searchString: any, position: any): boolean;
|
|
5
|
-
export declare function getPropertyNames(object: any): any[];
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {EspMetadata, EspDecoratorUtil} from 'esp-js';
|
|
2
|
-
|
|
3
|
-
export interface GetEspReactRenderModelMetadata {
|
|
4
|
-
functionName: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export namespace GetEspReactRenderModelConsts {
|
|
8
|
-
export const CustomDataKey = 'GetEspReactRenderModelCustomDataKey';
|
|
9
|
-
/**
|
|
10
|
-
* If there is no @getEspReactRenderModel decorator and a function by this name exists on a model, then it will be invoked to identify the sub model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
11
|
-
*/
|
|
12
|
-
export const HandlerFunctionName = 'getEspReactRenderModel';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A decorator which can be used to identify the render model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
17
|
-
*/
|
|
18
|
-
export function getEspReactRenderModel() {
|
|
19
|
-
return function (target, name, descriptor) {
|
|
20
|
-
let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);
|
|
21
|
-
metadata.addCustomData(
|
|
22
|
-
GetEspReactRenderModelConsts.CustomDataKey,
|
|
23
|
-
<GetEspReactRenderModelMetadata>{ functionName: name }
|
|
24
|
-
);
|
|
25
|
-
return descriptor;
|
|
26
|
-
};
|
|
27
|
-
}
|
package/src/routerProvider.tsx
DELETED
|
@@ -1,47 +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
|
-
import * as React from 'react';
|
|
20
|
-
import * as PropTypes from 'prop-types';
|
|
21
|
-
import { Router } from 'esp-js';
|
|
22
|
-
import {useContext} from 'react';
|
|
23
|
-
|
|
24
|
-
export interface RouterProviderProps {
|
|
25
|
-
router: Router;
|
|
26
|
-
// React 18 Fix:
|
|
27
|
-
// The current codebase is React 16, it will work with React 18, but there were changes to the types in React 18.
|
|
28
|
-
// The `children` prop was removed from some React types that cause the RouterProvider to fail, this fixes that.
|
|
29
|
-
children: any;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const RouterContext = React.createContext<Router>(null);
|
|
33
|
-
export const useRouter = () => useContext(RouterContext);
|
|
34
|
-
|
|
35
|
-
export class RouterProvider extends React.Component<RouterProviderProps, any> {
|
|
36
|
-
static childContextTypes = {
|
|
37
|
-
router: PropTypes.instanceOf(Router).isRequired
|
|
38
|
-
};
|
|
39
|
-
getChildContext() {
|
|
40
|
-
return {
|
|
41
|
-
router: this.props.router
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
render() {
|
|
45
|
-
return (<RouterContext.Provider value={this.props.router}>{this.props.children}</RouterContext.Provider>);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/shallowEqual.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// taken from fbjs:
|
|
2
|
-
// https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js
|
|
3
|
-
// Licence (MIT) https://github.com/facebook/fbjs/blob/master/packages/fbjs/LICENSE
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*
|
|
10
|
-
* @providesModule shallowEqual
|
|
11
|
-
* @typechecks
|
|
12
|
-
* @flow
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/*eslint-disable no-self-compare */
|
|
16
|
-
|
|
17
|
-
'use strict';
|
|
18
|
-
|
|
19
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
23
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
24
|
-
*/
|
|
25
|
-
export function is(x: any, y: any): boolean {
|
|
26
|
-
// SameValue algorithm
|
|
27
|
-
if (x === y) { // Steps 1-5, 7-10
|
|
28
|
-
// Steps 6.b-6.e: +0 != -0
|
|
29
|
-
// Added the nonzero y check to make Flow happy, but it is redundant
|
|
30
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
31
|
-
} else {
|
|
32
|
-
// Step 6.a: NaN == NaN
|
|
33
|
-
return x !== x && y !== y;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Performs equality by iterating through keys on an object and returning false
|
|
39
|
-
* when any key has values which are not strictly equal between the arguments.
|
|
40
|
-
* Returns true when the values of all keys are strictly equal.
|
|
41
|
-
*/
|
|
42
|
-
export function shallowEqual(objA, objB) {
|
|
43
|
-
if (is(objA, objB)) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (typeof objA !== 'object' || objA === null ||
|
|
48
|
-
typeof objB !== 'object' || objB === null) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const keysA = Object.keys(objA);
|
|
53
|
-
const keysB = Object.keys(objB);
|
|
54
|
-
|
|
55
|
-
if (keysA.length !== keysB.length) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Test for A's keys different from B.
|
|
60
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
61
|
-
if (
|
|
62
|
-
!hasOwnProperty.call(objB, keysA[i]) ||
|
|
63
|
-
!is(objA[keysA[i]], objB[keysA[i]])
|
|
64
|
-
) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
}
|