Skip to content

Commit 27bc94b

Browse files
Martynas ŽilinskasDovydasNavickas
authored andcommitted
Removed Submit method in base-form. Moved it's contents to form-store to handle submit result.
1 parent 7c0a5d5 commit 27bc94b

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"private": true,
44
"scripts": {},
55
"devDependencies": {
6-
"babel-core": "^6.24.1",
7-
"babel-preset-es2015": "^6.24.1",
8-
"gulp": "github:gulpjs/gulp#4.0",
96
"lerna": "2.0.0-rc.1",
10-
"typescript": "2.3.0",
11-
"webpack-stream": "^3.2.0"
7+
"typescript": "2.3.0"
128
}
139
}

packages/simplr-forms-core/src/abstractions/base-form.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ export abstract class BaseForm<TProps extends FormContracts.FormProps, TState> e
4444
return this.FormStore.GetState().Form.Error == null;
4545
}
4646

47-
protected async Submit(result: Promise<void> | FormError | any): Promise<void> {
48-
let promise: Promise<void>;
49-
if (this.isPromise<void>(result)) {
50-
promise = result;
51-
} else {
52-
promise = new Promise<void>((resolve, reject) => {
53-
const error = ConstructFormError(result);
54-
if (error !== undefined) {
55-
reject(result);
56-
return;
57-
}
58-
resolve(result);
59-
});
60-
}
61-
await this.FormStore.Submit(promise);
62-
}
63-
6447
componentWillUnmount() {
6548
if (this.props.destroyOnUnmount) {
6649
this.FormStoresHandler.UnregisterForm(this.FormId);
@@ -96,8 +79,4 @@ export abstract class BaseForm<TProps extends FormContracts.FormProps, TState> e
9679
}
9780
}
9881
}
99-
100-
private isPromise<T>(value: any): value is Promise<T> {
101-
return value != null && value.then != null && value.catch != null;
102-
}
10382
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,21 @@ export class FormStore extends ActionEmitter {
212212
this.State.Form.SubmitCallback();
213213
}
214214

215-
public async Submit(promise: Promise<void>) {
215+
public async Submit(result: Promise<void> | FormError | any) {
216+
let promise: Promise<void>;
217+
if (this.IsPromise<void>(result)) {
218+
promise = result;
219+
} else {
220+
promise = new Promise<void>((resolve, reject) => {
221+
const error = ConstructFormError(result);
222+
if (error !== undefined) {
223+
reject(result);
224+
return;
225+
}
226+
resolve(result);
227+
});
228+
}
229+
216230
// Form.Submitting -> true
217231
this.State = this.State.withMutations(state => {
218232
state.Form = state.Form.merge({
@@ -279,4 +293,8 @@ export class FormStore extends ActionEmitter {
279293
Props: undefined
280294
};
281295
}
296+
297+
protected IsPromise<T>(value: any): value is Promise<T> {
298+
return value != null && value.then != null && value.catch != null;
299+
}
282300
}

packages/simplr-forms-dom/src/components/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Form extends BaseForm<FormProps, {}> {
3636
event.persist();
3737

3838
const result = this.props.onSubmit(event, this.FormStore);
39-
this.Submit(result);
39+
this.FormStore.Submit(result);
4040
}
4141

4242
render() {

0 commit comments

Comments
 (0)