auto-views-with-ui-schema
Advanced tools
Comparing version 0.5.0 to 0.5.1
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
import { AutoViewProps } from '../auto-view'; | ||
import { CoreSchemaMetaSchema, SimpleTypes } from '../models'; | ||
import { CoreSchemaMetaSchema } from '../models'; | ||
export declare type JSONPointer = string; | ||
@@ -10,5 +10,5 @@ export declare type RepoName = string; | ||
} | ||
export declare type ComponentsRepoStorage<P> = { | ||
[K in SimpleTypes]: Array<ComponentRepoRecord<P>>; | ||
}; | ||
export interface ComponentsRepoStorage<P> { | ||
[type: string]: Array<ComponentRepoRecord<P>>; | ||
} | ||
export declare type Predicate = (node: CoreSchemaMetaSchema, ...rest: any[]) => boolean; | ||
@@ -23,6 +23,7 @@ export interface ComponentRepoRecord<P> { | ||
name: string; | ||
private getNodeType; | ||
private byType; | ||
private byName; | ||
constructor(name: string); | ||
register(type: SimpleTypes, record: ComponentRepoRecord<AutoViewProps>): this; | ||
constructor(name: string, getNodeType?: (node: any) => string); | ||
register(type: string, record: ComponentRepoRecord<AutoViewProps>): this; | ||
get(name: string): ComponentRepoRecord<AutoViewProps> | undefined; | ||
@@ -29,0 +30,0 @@ getMatched(node: CoreSchemaMetaSchema): ComponentRepoRecord<AutoViewProps>[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class ComponentsRepo { | ||
constructor(name) { | ||
constructor(name, getNodeType = node => node.type) { | ||
this.name = name; | ||
this.byType = { | ||
number: [], | ||
integer: [], | ||
string: [], | ||
null: [], | ||
boolean: [], | ||
object: [], | ||
array: [] | ||
}; | ||
this.getNodeType = getNodeType; | ||
this.byType = {}; | ||
this.byName = new Map(); | ||
} | ||
register(type, record) { | ||
this.byType[type].push(record); | ||
const registered = this.byType[type] || []; | ||
registered.push(record); | ||
this.byType[type] = registered; | ||
this.byName.set(record.name, record); | ||
@@ -26,14 +21,14 @@ return this; | ||
getMatched(node) { | ||
const { type } = node; | ||
if (typeof type !== 'string' || !(type in this.byType)) { | ||
const type = this.getNodeType(node); | ||
if (typeof type !== 'string') { | ||
return []; | ||
} | ||
return this.byType[type].filter(({ predicate = () => true }) => predicate(node)); | ||
const registered = this.byType[type] || []; | ||
return registered.filter(({ predicate = () => true }) => predicate(node)); | ||
} | ||
registerCollection(components) { | ||
Object.keys(components) | ||
.forEach(type => { | ||
components[type] | ||
.forEach(componentRecord => this.register(type, componentRecord)); | ||
}); | ||
Object | ||
.keys(components) | ||
.forEach(type => components[type] | ||
.forEach(componentRecord => this.register(type, componentRecord))); | ||
return this; | ||
@@ -40,0 +35,0 @@ } |
{ | ||
"name": "auto-views-with-ui-schema", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "", | ||
@@ -10,3 +10,3 @@ "main": "./dist/index.js", | ||
"build": "run-s clean && tsc -p tsconfig.prod.json && stc --srcDir=src --outDir=dist/src --diagnostics", | ||
"prepublish": "run-p lint build", | ||
"prepublish": "run-s lint build", | ||
"lint": "tslint \"@(src|test|stories)/**/*.ts?(x)\" -c tslint.json -p tsconfig.json", | ||
@@ -13,0 +13,0 @@ "test": "run-s lint test:browser", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
148533
1319