Skip to content

Commit

Permalink
fix(react): inital generated docs for better dev experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Igmat committed Sep 18, 2018
1 parent 3e8f218 commit e813162
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/react/src/ApplicationRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@ import { IOverrideResult } from 'metaf-resolvable';
import { Component } from 'react';
import { HOC, IRequirementsOverride, resolver } from './Resolver';

/**
* // TODO: comment IApplicationRootProps
* @description application root props
*/
export interface IApplicationRootProps {

/**
* // TODO: comment dependencies
* @description
*/
dependencies: IOverrideResult[];

/**
* // TODO: comment requirements
* @description
*/
requirements: IRequirementsOverride[];
}

interface IApplicationRootState {
hocs: HOC[];
}

/**
* // TODO: comment ApplicationRoot
* @description Application root
*/
export class ApplicationRoot extends Component<IApplicationRootProps, IApplicationRootState> {

/**
* // TODO: comment defaultProps
* @description Default props of application root
*/
static defaultProps = {
dependencies: [],
requirements: [],
Expand All @@ -19,12 +43,23 @@ export class ApplicationRoot extends Component<IApplicationRootProps, IApplicati
* @internal
*/
protected resolver = resolver;

/**
* Creates an instance of application root.
* @param props
*/
constructor(props: Readonly<IApplicationRootProps>) {
super(props);
this.resolver.setOverrides(props.dependencies);
this.resolver.setRequirementsOverrides(props.requirements);
this.resolver.subscribeForRequirements(this.requirementsUpdate);
}

/**
* // TODO: comment render
* @description Renders application root
* @returns
*/
render() {
return this.wrapInHocs();
}
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/MockRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ function resolveFor<I extends MetafResolvable.IInjections = {}>(
}

let isResolverFnChangedToMock = false;

/**
* // TODO: comment MockRoot
* @description Mock root
*/
export class MockRoot extends ApplicationRoot {

/**
* Creates an instance of mock root.
* @param props
*/
constructor(props: Readonly<IApplicationRootProps>) {
super(props);
if (!isResolverFnChangedToMock) {
Expand All @@ -79,6 +89,12 @@ export class MockRoot extends ApplicationRoot {
}
this.resolver = new ReactResolver(props.dependencies);
}

/**
* // TODO: comment render
* @description Renders mock root
* @returns
*/
render() {
return addPropsToAll(this.wrapInHocs(), this.resolver.resolveFor);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/ResolvableComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { IRequirements } from './Resolver';

export type ResolvableComponent<I extends IInjections> =
new <P = {}, S = {}, SS = any>(props: Readonly<P>) => AbstractResolvable<I> & Component<P, S, SS>;

/**
* // TODO: comment ResolvableComponent
* @description Resolvable component
* @template I
* @template R
* @param [injections]
* @param [requirements]
* @returns component
*/
export function ResolvableComponent<I extends IInjections = {}, R extends IRequirements = {}>(
injections: I = {} as I,
requirements: R = {} as R): ResolvableComponent<I> {
Expand Down
22 changes: 22 additions & 0 deletions packages/react/src/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@ import { Constructable, IDependencies, IInjections, IOverrideResult, Resolver, s
import { ReactNode } from 'react';

export type HOC = (app: ReactNode) => JSX.Element;

/**
* // TODO: comment IRequirements
* @description requirements
*/
export interface IRequirements { [index: string]: HOC; }
const requirementsOverride = Symbol('Requirements Override');

/**
* // TODO: comment IRequirementsOverride
* @description requirements override
* @template T
* @template R
*/
export interface IRequirementsOverride<T extends HOC = any, R extends T = any> {
[requirementsOverride]: [T, R];
}

/**
* // TODO: comment overrideRequirement
* @description Overrides requirement
* @template T
* @template R
* @param key
* @param value
* @returns requirement
*/
export function overrideRequirement<T extends HOC, R extends T>(key: T, value: R): IRequirementsOverride<T, R> {
return { [requirementsOverride]: [key, value] };
}
Expand Down

0 comments on commit e813162

Please sign in to comment.