From a97f57576620d5ae65aec2a66ea02077682c1e79 Mon Sep 17 00:00:00 2001 From: Rauli L Date: Tue, 10 Oct 2017 23:00:22 +0300 Subject: [PATCH] Add type definitions for RE:DOM 3.6 (#20469) 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. --- types/redom/index.d.ts | 69 ++++++++++++++++++++++++++++++++++++++ types/redom/redom-tests.ts | 16 +++++++++ types/redom/tsconfig.json | 25 ++++++++++++++ types/redom/tslint.json | 1 + 4 files changed, 111 insertions(+) create mode 100644 types/redom/index.d.ts create mode 100644 types/redom/redom-tests.ts create mode 100644 types/redom/tsconfig.json create mode 100644 types/redom/tslint.json diff --git a/types/redom/index.d.ts b/types/redom/index.d.ts new file mode 100644 index 0000000000..24e149258e --- /dev/null +++ b/types/redom/index.d.ts @@ -0,0 +1,69 @@ +// Type definitions for redom 3.6 +// Project: https://github.com/redom/redom/ +// Definitions by: Rauli Laine +// 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; diff --git a/types/redom/redom-tests.ts b/types/redom/redom-tests.ts new file mode 100644 index 0000000000..0ec18f6a59 --- /dev/null +++ b/types/redom/redom-tests.ts @@ -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!')); diff --git a/types/redom/tsconfig.json b/types/redom/tsconfig.json new file mode 100644 index 0000000000..65b279f902 --- /dev/null +++ b/types/redom/tsconfig.json @@ -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" + ] +} diff --git a/types/redom/tslint.json b/types/redom/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/redom/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }