diff --git a/package.json b/package.json index 6938788..12da9a9 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,11 @@ "/src" ] }, + "repository" : + { + "type" : "git", + "url" : "https://github.com/npm/npm.git" + }, "devDependencies": { "babel-cli": "^6.18.0", "babel-core": "^6.18.2", diff --git a/src/__tests__/validatePayload.test.js b/src/__tests__/validatePayload.test.js index ca8b328..f4879ae 100644 --- a/src/__tests__/validatePayload.test.js +++ b/src/__tests__/validatePayload.test.js @@ -18,6 +18,10 @@ describe('Validation functionality', () => { it('Boolean primitive should allow for string', () => { expect(validatePrimitive(Types.boolean(), true)).toBe(true); }); + it('Any should allow for anything', () => { + const date = new Date(); + expect(validatePrimitive(Types.any(), date)).toEqual(date); + }) }); describe('Arrays', () => { diff --git a/src/reducers.js b/src/reducers.js index c5b8148..8b6e0c4 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -48,6 +48,7 @@ export const REDUCER_CREATOR_MAPPING: { [key: PropTypeKeys]: any } = { [PROP_TYPES._boolean]: createPrimitiveReducer, [PROP_TYPES._string]: createPrimitiveReducer, [PROP_TYPES._number]: createPrimitiveReducer, + [PROP_TYPES._any]: createPrimitiveReducer, }; diff --git a/src/structure.js b/src/structure.js index fe60fd2..f67ffef 100644 --- a/src/structure.js +++ b/src/structure.js @@ -29,19 +29,8 @@ export type PrimitiveType = () => { structure?: PrimitiveType, }; export type TypesObject = { - [key: string]: CreateArrayType | CreateStringType | CreateNumberType | CreateShapeType | CreateBooleanType; -} - -export type TypesObjectDefaults = { - [key: string]: mixed | TypesArrayDefaults, -} -export type TypesArrayDefaults = Array | Array; - -type CreateStringType = (defaultValue: string) => PrimitiveType; -type CreateNumberType = (defaultValue: number) => PrimitiveType; -type CreateBooleanType = (defaultValue: boolean) => PrimitiveType; -type CreateArrayType = (structure: StructureType | PrimitiveType, defaultValue: TypesArrayDefaults | TypesObjectDefaults) => StructureType; -type CreateShapeType = (structure: ShapeStructure, defaultValue: TypesArrayDefaults | TypesObjectDefaults) => StructureType; + [key: string]: any, +}; //============================== // Structure @@ -53,6 +42,7 @@ export const PROP_TYPES = { _reducer: '_reducer', _shape: '_shape', _array: '_array', + _any: '_any', }; //The types objects are used in order to build up the structure of a store chunk, and provide/accept @@ -73,6 +63,11 @@ export const Types: TypesObject = { defaultValue, typeofValue: 'boolean', }), + any: (defaultValue: any = null) => () => ({ + type: PROP_TYPES._any, + defaultValue, + typeofValue: 'any', + }), arrayOf: (structure: StructureType | PrimitiveType, defaultValue = []) => () => ({ type: PROP_TYPES._array, structure, diff --git a/src/validatePayload.js b/src/validatePayload.js index f3c6fab..bfac665 100644 --- a/src/validatePayload.js +++ b/src/validatePayload.js @@ -46,7 +46,7 @@ export function validateShape(objectStructure: any, value: mixed): Object { export function validatePrimitive(primitive: any, value: any): mixed { //Validate primitives using the typeofValue property of the primitive type definitions. - if (typeof value === primitive().typeofValue ) return value; + if (typeof value === primitive().typeofValue || primitive().typeofValue === 'any') return value; return console.warn(`The value, ${value}, did not match the type specified (${primitive().type}).`); } @@ -71,6 +71,7 @@ export function getTypeValidation(type: string): validationFunction { [PROP_TYPES._boolean]: validatePrimitive, [PROP_TYPES._array]: validateArray, [PROP_TYPES._shape]: validateShape, + [PROP_TYPES._any]: validatePrimitive, }; const typeValidation = TYPE_VALIDATIONS[type]; if (!typeValidation) {