Skip to content

Commit da2b41c

Browse files
GetFieldId, GetFieldsGroupId and GetFieldsArrayId moved to helpers. (#84)
* GetFieldId, GetFieldsGroupId and GetFieldsArrayId moved to helpers. * Main package.json scripts fixed.
1 parent 34da9f4 commit da2b41c

File tree

7 files changed

+42
-43
lines changed

7 files changed

+42
-43
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"private": true,
44
"scripts": {
55
"generate": "rush generate",
6-
"tools-build": "npm run rush-tools run gulp-build -e simplr-mvdir",
7-
"source-build": "npm run rush-tools run build -e simplr-mvdir",
8-
"test": "npm run rush-tools run test-tsc -e simplr-mvdir",
6+
"tools-build": "npm run rush-tools -- run gulp-build -e simplr-mvdir",
7+
"source-build": "npm run rush-tools -- run build -e simplr-mvdir",
8+
"test": "npm run rush-tools -- run test-tsc -e simplr-mvdir",
99
"rush-tools": "ts-node ./tools/rush-tools.ts",
10-
"publish": "npm run rush-tools publish"
10+
"publish": "npm run rush-tools -- publish"
1111
},
1212
"devDependencies": {
1313
"@microsoft/rush": "^3.0.9",

packages/simplr-forms-dom/src/abstractions/base-dom-field.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import {
88
} from "../contracts/field";
99
import { FormProps } from "../contracts/form";
1010

11-
12-
export interface BaseDomFieldState extends BaseFieldState {
13-
14-
}
11+
export interface BaseDomFieldState extends BaseFieldState { }
1512

1613
export abstract class BaseDomField<TProps extends DomFieldProps, TState extends BaseDomFieldState, TUnderlyingElement = any>
1714
extends BaseField<TProps, TState> {

packages/simplr-forms/src/abstractions/base-fields-array.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FieldsGroupChildContext } from "../contracts/fields-group";
88
import { FieldContext } from "../contracts/field";
99
import { FSHContainer } from "../stores/form-stores-handler";
1010
import { FormStore } from "../stores/form-store";
11+
import { FormStoreHelpers } from "../stores/form-store-helpers";
1112
import * as PropTypes from "prop-types";
1213

1314
export class BaseFieldsArray<TProps extends FieldsArrayProps,
@@ -49,7 +50,7 @@ export class BaseFieldsArray<TProps extends FieldsArrayProps,
4950

5051
componentWillMount() {
5152
const idBase = `${this.props.name}[${this.props.index}]`;
52-
this.FieldsArrayId = this.FormStore.GetFieldsGroupId(idBase, this.context.FieldsGroupId);
53+
this.FieldsArrayId = FormStoreHelpers.GetFieldsGroupId(idBase, this.context.FieldsGroupId);
5354
this.FormStore.RegisterFieldsArray(this.FieldsArrayId, this.props.name, this.props.index, this.context.FieldsGroupId);
5455
}
5556

packages/simplr-forms/src/abstractions/base-fields-group.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FieldContext } from "../contracts/field";
99
import { FSHContainer } from "../stores/form-stores-handler";
1010
import { FormStore } from "../stores/form-store";
1111
import * as PropTypes from "prop-types";
12+
import { FormStoreHelpers } from "../stores/form-store-helpers";
1213

1314
export class BaseFieldsGroup<TProps extends FieldsGroupProps,
1415
TState extends FieldsGroupState>
@@ -48,7 +49,7 @@ export class BaseFieldsGroup<TProps extends FieldsGroupProps,
4849
}
4950

5051
componentWillMount() {
51-
this.FieldsGroupId = this.FormStore.GetFieldsGroupId(this.props.name, this.context.FieldsGroupId);
52+
this.FieldsGroupId = FormStoreHelpers.GetFieldsGroupId(this.props.name, this.context.FieldsGroupId);
5253
this.FormStore.RegisterFieldsGroup(this.FieldsGroupId, this.props.name, this.context.FieldsGroupId);
5354
}
5455

packages/simplr-forms/src/abstractions/core-field.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import {
1919
} from "../contracts/form";
2020
import { FormStore } from "../stores/form-store";
2121
import * as FormStoreActions from "../actions/form-store";
22-
// import { FieldsGroupContextProps } from "../contracts/fields-group";
2322
import { FSHContainer } from "../stores/form-stores-handler";
2423
import { FieldValidationType } from "../contracts/validation";
2524
import { FormStoreStateRecord } from "../contracts/form-store";
2625
import { ModifierValue } from "../contracts/value";
26+
import { FormStoreHelpers } from "../stores/form-store-helpers";
2727

2828
export interface CoreFieldState {
2929
FormStoreState: FormStoreStateRecord;
@@ -75,7 +75,7 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
7575
}
7676

7777
protected get FieldId(): string {
78-
return this.FormStore.GetFieldId(this.props.name, this.FieldsGroupId);
78+
return FormStoreHelpers.GetFieldId(this.props.name, this.FieldsGroupId);
7979
}
8080

8181
protected get FieldsGroupId(): string {

packages/simplr-forms/src/stores/form-store-helpers.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
import * as React from "react";
22
import { FieldStorePropsRecord } from "../contracts/field";
33

4+
export const FIELDS_GROUP_SEPARATOR = ".";
5+
46
export class FormStoreHelpers {
7+
/**
8+
* Constructs field id from given fieldName and an optional fieldsGroupIdkds
9+
*
10+
* @param {string} fieldName
11+
* @param {string} [fieldsGroupId]
12+
* @returns Constructed field id
13+
*
14+
* @memberOf FormStore
15+
*/
16+
public static GetFieldId(fieldName: string, fieldsGroupId?: string): string {
17+
if (fieldsGroupId != null) {
18+
return `${fieldsGroupId}${FIELDS_GROUP_SEPARATOR}${fieldName}`;
19+
}
20+
21+
return fieldName;
22+
}
23+
24+
public static GetFieldsGroupId(name: string, parentId?: string): string {
25+
if (parentId != null) {
26+
return `${parentId}${FIELDS_GROUP_SEPARATOR}${name}`;
27+
}
28+
29+
return name;
30+
}
31+
32+
public static GetFieldsArrayId(name: string, parentId?: string): string {
33+
return this.GetFieldsGroupId(name, parentId);
34+
}
35+
536
protected static ArrayUnique<T>(array: T[], concat: boolean = true): T[] {
637
let result = concat ? array.concat() : array;
738
for (var i = 0; i < result.length; ++i) {

packages/simplr-forms/src/stores/form-store.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import { ConstructFormError } from "../utils/form-error-helpers";
3333
import { FormError, FormErrorRecord, FormErrorOrigin } from "../contracts/error";
3434
import { ModifierValue } from "../contracts/value";
3535

36-
export const FG_SEPARATOR = ".";
37-
3836
export type Dictionary<TItem = any> = { [key: string]: TItem };
3937

4038
export class FormStore extends ActionEmitter {
@@ -70,35 +68,6 @@ export class FormStore extends ActionEmitter {
7068
* ========================
7169
*/
7270

73-
/**
74-
* Constructs field id from given fieldName and an optional fieldsGroupIdkds
75-
*
76-
* @param {string} fieldName
77-
* @param {string} [fieldsGroupId]
78-
* @returns Constructed field id
79-
*
80-
* @memberOf FormStore
81-
*/
82-
public GetFieldId(fieldName: string, fieldsGroupId?: string): string {
83-
if (fieldsGroupId != null) {
84-
return `${fieldsGroupId}${FG_SEPARATOR}${fieldName}`;
85-
}
86-
87-
return fieldName;
88-
}
89-
90-
public GetFieldsGroupId(name: string, parentId?: string): string {
91-
if (parentId != null) {
92-
return `${parentId}${FG_SEPARATOR}${name}`;
93-
}
94-
95-
return name;
96-
}
97-
98-
public GetFieldsArrayId(name: string, parentId?: string): string {
99-
return this.GetFieldsGroupId(name, parentId);
100-
}
101-
10271
public RegisterField(
10372
fieldId: string,
10473
name: string,

0 commit comments

Comments
 (0)