esp-js-react 8.1.1-next.0 → 9.0.0-beta.3
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.esm.mjs +710 -0
- package/.dist/esp-react.esm.mjs.map +1 -0
- package/.dist/esp-react.js +695 -777
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +2 -3
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/connectableComponent.d.ts +8 -9
- package/.dist/typings/espApp.d.ts +25 -0
- package/.dist/typings/espEventBusContextProvider.d.ts +41 -0
- package/.dist/typings/espModulesContext.d.ts +3 -0
- package/.dist/typings/espStoreContextProvider.d.ts +62 -0
- package/.dist/typings/index.d.ts +13 -9
- package/.dist/typings/regionView.d.ts +19 -0
- package/.dist/typings/useSyncStoreModelWithSelector.d.ts +47 -0
- package/README.md +62 -22
- package/package.json +63 -45
- package/.dist/esp-react.min.js.LICENSE.txt +0 -9
- package/.dist/typings/connect.d.ts +0 -8
- package/.dist/typings/espModelContextProvider.d.ts +0 -63
- package/.dist/typings/espRouterContextProvider.d.ts +0 -54
- package/.dist/typings/polimer/polimerModelBuilderExtentsions.d.ts +0 -6
- package/.dist/typings/useSyncModelWithSelector.d.ts +0 -52
- package/.dist/typings/viewBinder.d.ts +0 -13
- package/.dist/typings/viewBindingDecorator.d.ts +0 -34
- package/.yarnignore +0 -15
- package/docs/images/esp-agile-demo.gif +0 -0
- package/jest.config.js +0 -19
- package/src/connect.tsx +0 -27
- package/src/connectableComponent.tsx +0 -99
- package/src/espModelContextProvider.tsx +0 -101
- package/src/espRouterContextProvider.tsx +0 -97
- package/src/index.ts +0 -68
- package/src/polimer/polimerModelBuilderExtentsions.ts +0 -36
- package/src/useSyncModelWithSelector.ts +0 -223
- package/src/viewBinder.tsx +0 -51
- package/src/viewBindingDecorator.ts +0 -113
- package/tests/connectableComponentTests.tsx +0 -477
- package/tests/espModelContextProviderTests.tsx +0 -150
- package/tests/espRouterContextProviderTests.tsx +0 -56
- package/tests/indexTests.ts +0 -47
- package/tests/testApi/asserts.ts +0 -102
- package/tests/testApi/routerSpy.ts +0 -24
- package/tests/testApi/testApi.tsx +0 -100
- package/tests/testApi/testModel.ts +0 -43
- package/tests/testApi/useStoreReceivedProps.ts +0 -14
- package/tests/testApi/viewFactory.tsx +0 -31
- package/tests/useSyncModelWithSelectorTests.tsx +0 -330
- package/tests/viewBinderTests.tsx +0 -61
- package/tsconfig.json +0 -14
- package/webpack.config.js +0 -27
package/tests/indexTests.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// notice_start
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2018 Keith Woods
|
|
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 espReact from '../src/index';
|
|
20
|
-
|
|
21
|
-
describe('index exports', () => {
|
|
22
|
-
it('check exports', () => {
|
|
23
|
-
expect(espReact.viewBinding).toBeDefined();
|
|
24
|
-
expect(espReact.ViewBinder).toBeDefined();
|
|
25
|
-
expect(espReact.DEFAULT_VIEW_KEY).toBeDefined();
|
|
26
|
-
expect(espReact.createViewForModel).toBeDefined();
|
|
27
|
-
expect(espReact.connect).toBeDefined();
|
|
28
|
-
expect(espReact.ConnectableComponent).toBeDefined();
|
|
29
|
-
expect(espReact.useSyncModelWithSelector).toBeDefined();
|
|
30
|
-
expect(espReact.syncModelWithSelectorOptions).toBeDefined();
|
|
31
|
-
expect(espReact.RouterProvider).toBeDefined();
|
|
32
|
-
expect(espReact.EspRouterContextProvider).toBeDefined();
|
|
33
|
-
expect(espReact.RouterContext).toBeDefined();
|
|
34
|
-
expect(espReact.useRouter).toBeDefined();
|
|
35
|
-
expect(espReact.PublishEventContext).toBeDefined();
|
|
36
|
-
expect(espReact.usePublishEvent).toBeDefined();
|
|
37
|
-
expect(espReact.useGetModelId).toBeDefined();
|
|
38
|
-
expect(espReact.GetModelIdContext).toBeDefined();
|
|
39
|
-
expect(espReact.useGetModel).toBeDefined();
|
|
40
|
-
expect(espReact.GetModelContext).toBeDefined();
|
|
41
|
-
expect(espReact.PublishModelEventContext).toBeDefined();
|
|
42
|
-
expect(espReact.usePublishModelEvent).toBeDefined();
|
|
43
|
-
expect(espReact.PublishModelEventWithEntityKeyContext).toBeDefined();
|
|
44
|
-
expect(espReact.usePublishModelEventWithEntityKey).toBeDefined();
|
|
45
|
-
expect(espReact.EspModelContextProvider).toBeDefined();
|
|
46
|
-
});
|
|
47
|
-
});
|
package/tests/testApi/asserts.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {RenderResult} from '@testing-library/react';
|
|
2
|
-
// import for extra asserts
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import {RouterSpy} from './routerSpy';
|
|
5
|
-
import {TestPropStore} from './useStoreReceivedProps';
|
|
6
|
-
|
|
7
|
-
export type ViewAsserts = {
|
|
8
|
-
modelIdIs(expected: string): ViewAsserts
|
|
9
|
-
modelIdIsNotInDom(): ViewAsserts
|
|
10
|
-
valueIs(expected: string): ViewAsserts;
|
|
11
|
-
valueIsNotInDom(): ViewAsserts;
|
|
12
|
-
propIs(propName: string, expected: string): ViewAsserts
|
|
13
|
-
viewNameElementTextIs(viewName: string);
|
|
14
|
-
htmlElementInnerTextIs(elementsTestId: string, expectedText: string): ViewAsserts
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const viewAsserts = (renderResult: RenderResult) => {
|
|
18
|
-
return {
|
|
19
|
-
modelIdIs(expected: string) {
|
|
20
|
-
let idElement = renderResult.getByTestId('modelIdDisplay');
|
|
21
|
-
expect(idElement).toHaveTextContent(expected);
|
|
22
|
-
return this;
|
|
23
|
-
},
|
|
24
|
-
modelIdIsNotInDom() {
|
|
25
|
-
let idElement = renderResult.queryByTestId('modelIdDisplay');
|
|
26
|
-
expect(idElement).not.toBeInTheDocument();
|
|
27
|
-
return this;
|
|
28
|
-
},
|
|
29
|
-
valueIs(expected: string) {
|
|
30
|
-
let valueElement = renderResult.getByTestId('valueDisplay');
|
|
31
|
-
expect(valueElement).toHaveTextContent(expected);
|
|
32
|
-
return this;
|
|
33
|
-
},
|
|
34
|
-
valueIsNotInDom() {
|
|
35
|
-
let idElement = renderResult.queryByTestId('valueDisplay');
|
|
36
|
-
expect(idElement).not.toBeInTheDocument();
|
|
37
|
-
return this;
|
|
38
|
-
},
|
|
39
|
-
propIs(propName: string, expected: string) {
|
|
40
|
-
let span = renderResult.getByTestId('span-with-props-as-attributes');
|
|
41
|
-
let attributeName = `data-${propName}`;
|
|
42
|
-
if (!span.hasAttribute(attributeName)) {
|
|
43
|
-
let error = `Span doesn't have attribute '${attributeName}'. Has ${JSON.stringify(span.attributes)}`;
|
|
44
|
-
fail(error);
|
|
45
|
-
}
|
|
46
|
-
expect(span.getAttribute(attributeName)).toBe(expected);
|
|
47
|
-
return this;
|
|
48
|
-
},
|
|
49
|
-
viewNameElementTextIs(viewName: string) {
|
|
50
|
-
let span = renderResult.getByTestId('view-name');
|
|
51
|
-
expect(span).toHaveTextContent(viewName);
|
|
52
|
-
return this;
|
|
53
|
-
},
|
|
54
|
-
htmlElementInnerTextIs(elementsTestId: string, expectedText: string) {
|
|
55
|
-
let span = renderResult.getByTestId(elementsTestId);
|
|
56
|
-
expect(span).toHaveTextContent(expectedText);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
} as ViewAsserts;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type RouterAsserts = {
|
|
64
|
-
subscriberCountIs(modelId: string, expectedCount: number): RouterAsserts
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const routerAsserts = (routerSpy: RouterSpy) => {
|
|
68
|
-
return {
|
|
69
|
-
subscriberCountIs(modelId: string, expectedCount: number) {
|
|
70
|
-
if (expectedCount === 0) {
|
|
71
|
-
let modelNotSubscribed = routerSpy.getSubscriberCount(modelId) === undefined || routerSpy.getSubscriberCount(modelId) === 0;
|
|
72
|
-
expect(modelNotSubscribed).toBeTruthy();
|
|
73
|
-
} else {
|
|
74
|
-
expect(routerSpy.getSubscriberCount(modelId)).toEqual(expectedCount);
|
|
75
|
-
}
|
|
76
|
-
return this;
|
|
77
|
-
},
|
|
78
|
-
} as RouterAsserts;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export type PropAsserts = {
|
|
82
|
-
receivedPropCountIs(expectedCount: number): PropAsserts;
|
|
83
|
-
propAtIndex(index: number, asserter: (props) => void): PropAsserts
|
|
84
|
-
propAtIndexHasModelId(index: number, expectedModelId: string): PropAsserts
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const propAsserts = (testPropStore: TestPropStore) => {
|
|
88
|
-
return {
|
|
89
|
-
receivedPropCountIs(expectedCount: number) {
|
|
90
|
-
expect(testPropStore.receivedProps.length).toEqual(expectedCount);
|
|
91
|
-
return this;
|
|
92
|
-
},
|
|
93
|
-
propAtIndex(index: number, asserter: (props) => void): PropAsserts {
|
|
94
|
-
asserter(testPropStore.receivedProps[index]);
|
|
95
|
-
return this;
|
|
96
|
-
},
|
|
97
|
-
propAtIndexHasModelId(index: number, expectedModelId: string): PropAsserts {
|
|
98
|
-
expect(testPropStore.receivedProps[index].modelId).toBe(expectedModelId);
|
|
99
|
-
return this;
|
|
100
|
-
},
|
|
101
|
-
} as PropAsserts;
|
|
102
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {Router, Observable} from 'esp-js';
|
|
2
|
-
|
|
3
|
-
export class RouterSpy extends Router {
|
|
4
|
-
private _modelSubscriptionCountByModelId = new Map<string, number>();
|
|
5
|
-
|
|
6
|
-
public getSubscriberCount(modelId: string) {
|
|
7
|
-
return this._modelSubscriptionCountByModelId.get(modelId);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public getModelObservable<TModel>(modelId: string): Observable<TModel> {
|
|
11
|
-
return Observable.create(o => {
|
|
12
|
-
let c1 = this._modelSubscriptionCountByModelId.get(modelId) || 0;
|
|
13
|
-
c1++;
|
|
14
|
-
this._modelSubscriptionCountByModelId.set(modelId, c1);
|
|
15
|
-
let subscription = super.getModelObservable(modelId).subscribe(o);
|
|
16
|
-
return () => {
|
|
17
|
-
let c2 = this._modelSubscriptionCountByModelId.get(modelId);
|
|
18
|
-
c2--;
|
|
19
|
-
this._modelSubscriptionCountByModelId.set(modelId, c2);
|
|
20
|
-
subscription.dispose();
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {TestModel} from './testModel';
|
|
2
|
-
import {RouterSpy} from './routerSpy';
|
|
3
|
-
import {render, RenderResult} from '@testing-library/react';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import {EspModelContextProvider, EspRouterContextProvider} from '../../src';
|
|
6
|
-
import {PropAsserts, propAsserts, RouterAsserts, routerAsserts, ViewAsserts, viewAsserts} from './asserts';
|
|
7
|
-
import {isValidElement, ReactElement} from 'react';
|
|
8
|
-
import {TestPropStore, TestPropStoreContext} from './useStoreReceivedProps';
|
|
9
|
-
|
|
10
|
-
export type TestApi = {
|
|
11
|
-
router: RouterSpy;
|
|
12
|
-
propStore: TestPropStore;
|
|
13
|
-
asserts: {
|
|
14
|
-
router: RouterAsserts,
|
|
15
|
-
view: ViewAsserts,
|
|
16
|
-
props: PropAsserts,
|
|
17
|
-
};
|
|
18
|
-
setupModel<TModel>(modelId: string, model: TModel): TModel;
|
|
19
|
-
setupTestModel(modelId: string): TestModel;
|
|
20
|
-
setupModelAndRender(modelId: string, Component: React.ComponentType): TestApi;
|
|
21
|
-
doRender(Component: React.ComponentType, modelIdForContext?: string): TestApi
|
|
22
|
-
doRender(Component: React.JSX.Element, modelIdForContext?: string): TestApi
|
|
23
|
-
doReRender(Component: React.ComponentType, modelIdForContext?: string, nextProps?: any): TestApi;
|
|
24
|
-
doReRender(Component: React.JSX.Element, modelIdForContext?: string, nextProps?: any): TestApi;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const testApi = ()=> {
|
|
28
|
-
let router: RouterSpy = new RouterSpy();
|
|
29
|
-
let renderResult: RenderResult;
|
|
30
|
-
let propStore = new TestPropStore();
|
|
31
|
-
return {
|
|
32
|
-
router,
|
|
33
|
-
propStore,
|
|
34
|
-
asserts: {
|
|
35
|
-
get router() {
|
|
36
|
-
return routerAsserts(router);
|
|
37
|
-
},
|
|
38
|
-
get view() {
|
|
39
|
-
return viewAsserts(renderResult);
|
|
40
|
-
},
|
|
41
|
-
get props() {
|
|
42
|
-
return propAsserts(propStore);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
setupModelAndRender(modelId: string, view: React.ComponentType) {
|
|
46
|
-
this.setupTestModel(modelId);
|
|
47
|
-
this.doRender(view, modelId);
|
|
48
|
-
return this;
|
|
49
|
-
},
|
|
50
|
-
setupModel<TModel>(modelId: string, model: TModel): TModel {
|
|
51
|
-
router.addModel(modelId, model);
|
|
52
|
-
router.observeEventsOn(modelId, model);
|
|
53
|
-
return model;
|
|
54
|
-
},
|
|
55
|
-
setupTestModel(modelId: string): TestModel {
|
|
56
|
-
const testModel = new TestModel(modelId);
|
|
57
|
-
router.addModel(modelId, testModel);
|
|
58
|
-
router.observeEventsOn(modelId, testModel);
|
|
59
|
-
return testModel;
|
|
60
|
-
},
|
|
61
|
-
doRender(ComponentOrElement: any, modelIdForContext?: string, nextProps?: any) {
|
|
62
|
-
let element: React.JSX.Element;
|
|
63
|
-
if (isValidElement(ComponentOrElement)) {
|
|
64
|
-
element = ComponentOrElement;
|
|
65
|
-
} else {
|
|
66
|
-
element = <ComponentOrElement />;
|
|
67
|
-
}
|
|
68
|
-
let elementWithProps = React.cloneElement(element, nextProps);
|
|
69
|
-
renderResult = render((
|
|
70
|
-
<TestPropStoreContext.Provider value={propStore}>
|
|
71
|
-
<EspRouterContextProvider router={router}>
|
|
72
|
-
<EspModelContextProvider modelId={modelIdForContext}>
|
|
73
|
-
{elementWithProps},
|
|
74
|
-
</EspModelContextProvider>
|
|
75
|
-
</EspRouterContextProvider>
|
|
76
|
-
</TestPropStoreContext.Provider>
|
|
77
|
-
));
|
|
78
|
-
return this;
|
|
79
|
-
},
|
|
80
|
-
doReRender(ComponentOrElement: any, modelIdForContext?: string, nextProps?: any) {
|
|
81
|
-
let element: React.JSX.Element;
|
|
82
|
-
if (isValidElement(ComponentOrElement)) {
|
|
83
|
-
element = ComponentOrElement;
|
|
84
|
-
} else {
|
|
85
|
-
element = <ComponentOrElement />;
|
|
86
|
-
}
|
|
87
|
-
let elementWithProps = React.cloneElement(element, nextProps);
|
|
88
|
-
renderResult.rerender((
|
|
89
|
-
<TestPropStoreContext.Provider value={propStore}>
|
|
90
|
-
<EspRouterContextProvider router={router}>
|
|
91
|
-
<EspModelContextProvider modelId={modelIdForContext}>
|
|
92
|
-
{elementWithProps},
|
|
93
|
-
</EspModelContextProvider>
|
|
94
|
-
</EspRouterContextProvider>
|
|
95
|
-
</TestPropStoreContext.Provider>
|
|
96
|
-
));
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
} as TestApi;
|
|
100
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {EventContext, observeEvent} from 'esp-js';
|
|
2
|
-
|
|
3
|
-
export type TestModelImmutableState = { value: string, modelId: string, entityKey: string };
|
|
4
|
-
|
|
5
|
-
export class TestModel {
|
|
6
|
-
|
|
7
|
-
private _internalState: TestModelImmutableState;
|
|
8
|
-
|
|
9
|
-
constructor(modelId: string) {
|
|
10
|
-
this._internalState = {
|
|
11
|
-
value: 'initial-value',
|
|
12
|
-
entityKey: '',
|
|
13
|
-
modelId: modelId,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public get state(): TestModelImmutableState {
|
|
18
|
-
return this._internalState;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@observeEvent('test-event')
|
|
22
|
-
_onTestEvent(ev: string) {
|
|
23
|
-
// mimic some immutable logic that would be provided by a lib such as immer in a real app.
|
|
24
|
-
this._internalState = {
|
|
25
|
-
...this._internalState,
|
|
26
|
-
value: ev
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@observeEvent('test-event-with-entity-key')
|
|
31
|
-
_onTestEventWithEntityKey(ev: string, eventContext: EventContext) {
|
|
32
|
-
// mimic some immutable logic that would be provided by a lib such as immer in a real app.
|
|
33
|
-
this._internalState = {
|
|
34
|
-
...this._internalState,
|
|
35
|
-
entityKey: eventContext.entityKey,
|
|
36
|
-
value: ev
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public getEspPolimerImmutableModel() {
|
|
41
|
-
return this._internalState;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {createContext, useContext} from 'react';
|
|
2
|
-
|
|
3
|
-
export const TestPropStoreContext = createContext<TestPropStore>(null);
|
|
4
|
-
export const useTestPropStore = () => useContext(TestPropStoreContext);
|
|
5
|
-
|
|
6
|
-
export class TestPropStore {
|
|
7
|
-
receivedProps: any[] = [];
|
|
8
|
-
pushProps(props: any) {
|
|
9
|
-
this.receivedProps.push(props);
|
|
10
|
-
}
|
|
11
|
-
getLastProps(): any {
|
|
12
|
-
return this.receivedProps[this.receivedProps.length -1];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {useTestPropStore} from './useStoreReceivedProps';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
export const viewFactory = (name: string) => {
|
|
5
|
-
return (props: { modelId?: string; value?: string, [key: string]: any }) => {
|
|
6
|
-
let testPropStore = useTestPropStore();
|
|
7
|
-
testPropStore.pushProps(props);
|
|
8
|
-
return (
|
|
9
|
-
<>
|
|
10
|
-
<span data-testid='view-name'>{name}</span>
|
|
11
|
-
<ViewMetadata modelId={props.modelId} modelValue={props.value} {...props}/>
|
|
12
|
-
</>
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type ViewMetadataProps = {
|
|
18
|
-
modelId: string,
|
|
19
|
-
modelValue: string
|
|
20
|
-
[key: string]: string; // ...rest props
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const ViewMetadata = (props: ViewMetadataProps) => {
|
|
24
|
-
const { modelId, modelValue, ...rest} = props;
|
|
25
|
-
return (
|
|
26
|
-
<div>
|
|
27
|
-
<span data-testid='modelIdDisplay'>{modelId}</span>
|
|
28
|
-
<span data-testid='valueDisplay'>{modelValue}</span>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
};
|