Skip to content

Commit

Permalink
Add type definitions for RE:DOM 3.6 (DefinitelyTyped#20469)
Browse files Browse the repository at this point in the history
Introduce new type definition package into repository which adds type
definitions for a library called RE:DOM. These type definitions are made
against RE:DOM version 3.6.2.
  • Loading branch information
RauliL authored and weswigham committed Oct 10, 2017
1 parent 226a61a commit a97f575
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
69 changes: 69 additions & 0 deletions types/redom/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Type definitions for redom 3.6
// Project: https://github.com/redom/redom/
// Definitions by: Rauli Laine <https://github.com/RauliL>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

export type RedomElement = Node | RedomComponent;
export type RedomQuery = string | RedomElement;
export type RedomMiddleware = (el: HTMLElement) => void;
export type RedomQueryArgumentValue = RedomElement | string | number | { [key: string]: any } | RedomMiddleware;
export type RedomQueryArgument = RedomQueryArgumentValue | RedomQueryArgumentValue[];

export interface RedomComponent {
el: HTMLElement;
}

export interface RedomComponentConstructor {
new (): RedomComponent;
}

export class List implements RedomComponent {
el: HTMLElement;

constructor(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any);

update(data: any[], context?: any): void;
}

export class Place implements RedomComponent {
el: HTMLElement;

constructor(View: RedomComponentConstructor, initData?: any);

update(visible: boolean, data?: any): void;
}

export class Router implements RedomComponent {
el: HTMLElement;

constructor(parent: RedomQuery, Views: RouterDictionary, initData?: any);

update(route: string, data?: any): void;
}

export interface RouterDictionary {
[key: string]: RedomComponentConstructor;
}

export function html(query: RedomQuery, ...args: RedomQueryArgument[]): HTMLElement;
export function el(query: RedomQuery, ...args: RedomQueryArgument[]): HTMLElement;

export function list(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): List;

export function mount(parent: RedomElement, child: RedomElement, before?: RedomElement): RedomElement;
export function unmount(parent: RedomElement, child: RedomElement): RedomElement;

export function place(View: RedomComponentConstructor, initData?: any): Place;

export function router(parent: RedomQuery, Views: RouterDictionary, initData?: any): Router;

export function setAttr(view: RedomElement, arg1: string | object, arg2?: string): void;

export function setStyle(view: RedomElement, arg1: string | object, arg2?: string): void;

export function setChildren(parent: RedomElement, children: RedomElement[]): void;

export function svg(query: RedomQuery, ...args: RedomQueryArgument[]): SVGElement;

export function text(str: string): Text;
16 changes: 16 additions & 0 deletions types/redom/redom-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as redom from 'redom';

const el1: HTMLElement = redom.el('');
const el2: HTMLElement = redom.el('p', 'Hello, World!', (el: HTMLElement) => { el.setAttribute('ok', '!'); });
const el3: HTMLElement = redom.html('p', 2, { color: 'red' });

redom.mount(document.body, el1);
redom.mount(document.body, el2, el1);
redom.unmount(document.body, el1);

redom.setAttr(el3, 'ok', '!');
redom.setAttr(el3, { ok: '!' });
redom.setStyle(el3, { color: 'blue' });
redom.setChildren(el1, [el2, el3]);

redom.mount(document.body, redom.text('Hello, World!'));
25 changes: 25 additions & 0 deletions types/redom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"redom-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/redom/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit a97f575

Please sign in to comment.