Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
Merge dev to master Version 0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevoss authored Jan 3, 2019
2 parents b237f76 + 4be00be commit 9e69412
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 181 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-wrapper-js",
"version": "0.6.1",
"version": "0.6.2",
"description": "JS abstraction for forms",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
2 changes: 1 addition & 1 deletion src/core/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorsStack } from '../types'
import { ErrorsStack } from '../types/Errors'

export class Errors {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/core/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import generateDefaultLabel from '../helpers/generateDefaultLabel'
import generateOptions from '../helpers/generateOptions'
import defaultOptions from '../default-options'
import basicInterceptors from '../interceptors/index'
import { Field } from '../types/Field'
import { FormDefaults } from '../types/Form'
import { Options } from '../types/Options'
import { SubmitCallback } from '../types/Form'
import {
Field,
FormDefaults,
InterceptorHandler,
InterceptorManagersObject,
Options,
SubmitCallback,
} from '../types'
} from '../types/Interceptors'

export class Form {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/InterceptorManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterceptorHandler } from '../types'
import { InterceptorHandler } from '../types/Interceptors'

export class InterceptorManager {
/**
Expand Down
6 changes: 4 additions & 2 deletions src/core/Validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isObject } from '../utils'
import { Field, Rule, RulesStack, ValidationOptions } from '../types'
import { Form } from './Form'
import { isObject } from '../utils'
import { Field } from '../types/Field'
import { Rule, RulesStack } from '../types/Validator'
import { ValidationOptions } from '../types/Options'

/**
* Validator Class
Expand Down
2 changes: 1 addition & 1 deletion src/default-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from './types'
import { Options } from './types/Options'

/**
* Default options that provide to Form instance
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/generateOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from '../types'
import { Options } from '../types/Options'
import { isObject } from '../utils'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/beforeSubmission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Form } from '../core/Form'
import { InterceptorHandler } from '../types'
import { InterceptorHandler } from '../types/Interceptors'

/**
* validate the form before submission
Expand Down
25 changes: 5 additions & 20 deletions src/interceptors/submissionComplete.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import { Form } from '../core/Form'
import { InterceptorHandler } from '../types'

/**
* The interface of an object with successful response from the
* SubmitCallback function
*/
interface successfulResponse {
form: Form
response: any
}

/**
* The interface of an object with unsuccessful response from the
* SubmitCallback function
*/
interface InvalidResponse {
form: Form
error: any
}
import {
InterceptorHandler,
InvalidResponse,
successfulResponse,
} from '../types/Interceptors'

/**
* set the $submitting property as false event if the submission
Expand Down
148 changes: 0 additions & 148 deletions src/types.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/types/Errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Field } from './Field'
import { Form } from '../core/Form'

/**
* Passes function is a prop in Rule Object
*/
export interface PassesFunction {
(field: Field, form: Form): boolean
}

/**
* Message function is a prop in the Rule Object
*/
export interface MessageFunction {
(field: Field, form: Form): string
}

/**
* Errors Stack must be a field key with an array of strings
*/
export interface ErrorsStack {
[fieldKey: string]: string[]
}
9 changes: 9 additions & 0 deletions src/types/Field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Field object that passes the PassesFunction and MessageFunction,
* it used in the Validator class.
*/
export interface Field {
key: string
label: string
value: any
}
20 changes: 20 additions & 0 deletions src/types/Form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Options } from './Options'
import { InterceptorManagersObject } from './Interceptors'
import { Form } from '../core/Form'

/**
* The defaults of the form,
* that can be changeable and then will affect on all the new Form instances
*/
export interface FormDefaults {
options: Options
interceptors: InterceptorManagersObject
}

/**
* Submit callback interface,
* the function the should pass to submit method in Form class
*/
export interface SubmitCallback {
(form: Form): Promise<any>
}
37 changes: 37 additions & 0 deletions src/types/Interceptors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { InterceptorManager } from '../core/InterceptorManager'
import { Form } from '../core/Form'

/**
* an object that hold 2 function one for fulfill and one for reject
*/
export interface InterceptorHandler {
fulfilled: Function
rejected: Function
}

/**
* an object that hold only InterceptorManagers as value
*/
export interface InterceptorManagersObject {
beforeSubmission: InterceptorManager
submissionComplete: InterceptorManager
[key: string]: InterceptorManager
}

/**
* The interface of an object with successful response from the
* SubmitCallback function
*/
export interface successfulResponse {
form: Form
response: any
}

/**
* The interface of an object with unsuccessful response from the
* SubmitCallback function
*/
export interface InvalidResponse {
form: Form
error: any
}
Loading

0 comments on commit 9e69412

Please sign in to comment.