Skip to content

Commit 17249a0

Browse files
simplr-forms-core packing updated to expose a convenient interface.
dist -> top level files moving implemented with a required externals resolving.
1 parent 75d1a34 commit 17249a0

File tree

15 files changed

+202
-33
lines changed

15 files changed

+202
-33
lines changed

packages/simplr-forms-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"enzyme": "^2.8.2",
3434
"jest": "^19.0.2",
3535
"jest-enzyme": "^3.0.1",
36+
"on-build-webpack": "^0.1.0",
3637
"react-dom": "^15.5.4",
3738
"react-test-renderer": "^15.5.4",
3839
"sinon": "^2.1.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./abstractions/index";
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from "react";
2+
import * as PropTypes from "prop-types";
3+
4+
import { FormStore } from "../stores/form-store";
5+
import { StateUpdated } from "../actions/form-store";
6+
import { FSHContainer } from "../stores/form-stores-handler";
7+
8+
export interface BaseContainerProps {
9+
formId: string;
10+
}
11+
12+
export interface BaseContainerParentContext {
13+
FormId: string;
14+
}
15+
16+
export abstract class BaseContainer<TProps extends BaseContainerProps, TState> extends React.Component<TProps, TState> {
17+
context: BaseContainerParentContext;
18+
19+
static contextTypes: PropTypes.ValidationMap<BaseContainerParentContext> = {
20+
FormId: PropTypes.string.isRequired
21+
};
22+
23+
protected get FormId(): string {
24+
if (this.props.formId == null) {
25+
return this.props.formId;
26+
}
27+
if (this.context.FormId != null) {
28+
return this.context.FormId;
29+
}
30+
31+
// Should never happen as componentWillMount handles this situation
32+
throw new Error(`simplr-forms-core: form id is not present neither in props, nor in context.`);
33+
}
34+
35+
protected get FormStore(): FormStore {
36+
return FSHContainer.FormStoresHandler.GetStore(this.FormId);
37+
}
38+
39+
componentWillMount() {
40+
if (this.props.formId == null && this.context.FormId == null) {
41+
throw new Error("simplr-forms-core: Container must be in a Form or have prop 'formId' set.");
42+
}
43+
44+
45+
if (this.props.formId != null && this.context.FormId != null) {
46+
const but = `but form id was defined: '${this.props.formId}'`;
47+
throw new Error(`simplr-forms-core: Container is already in a Form '${this.context.FormId}' context, ${but}.`);
48+
}
49+
50+
this.FormStore.addListener(StateUpdated, this.OnStoreUpdated.bind(this));
51+
}
52+
53+
protected abstract OnStoreUpdated(): void;
54+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./base-field";
22
export * from "./base-form";
3+
export * from "./base-container";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./actions/index";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./contracts/index";
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
import * as Abstractions from "./abstractions/index";
2-
import * as Actions from "./actions/index";
3-
import * as Contracts from "./contracts/index";
4-
import * as Stores from "./stores/index";
5-
import * as Utils from "./utils/index";
6-
7-
export {
8-
Abstractions,
9-
Actions,
10-
Contracts,
11-
Stores,
12-
Utils
13-
};
1+
export * from "./abstractions/index";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./stores/index";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./utils/index";

packages/simplr-forms-core/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"sourceMap": false,
1010
"skipDefaultLibCheck": true,
1111
"declaration": true,
12-
"declarationDir": "@types",
1312
"pretty": true,
1413
"strict": true,
1514
"lib": [

0 commit comments

Comments
 (0)