redom: Provides its own types (#39534)

This commit is contained in:
Alexander T 2019-10-30 00:14:40 +02:00 committed by Jesse Trinity
parent 91c3deba3c
commit fc00a1eb58
5 changed files with 6 additions and 168 deletions

View File

@ -3456,6 +3456,12 @@
"sourceRepoURL": "https://github.com/sindresorhus/redent",
"asOfVersion": "3.0.0"
},
{
"libraryName": "redom",
"typingsPackageName": "redom",
"sourceRepoURL": "https://github.com/redom/redom/",
"asOfVersion": "3.23.0"
},
{
"libraryName": "reduce-reducers",
"typingsPackageName": "reduce-reducers",

103
types/redom/index.d.ts vendored
View File

@ -1,103 +0,0 @@
// Type definitions for redom 3.12
// Project: https://github.com/redom/redom/, https://redom.js.org
// Definitions by: Rauli Laine <https://github.com/RauliL>
// Felix Nehrke <https://github.com/nemoinho>
// 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;
update?(item: any, index: number, data: any, context?: any): void;
onmount?(): void;
onremount?(): void;
onunmount?(): void;
}
export interface RedomComponentConstructor {
new (): RedomComponent;
}
export class ListPool {
constructor(View: RedomComponentConstructor, key?: string, initData?: any);
update(data: any[], context?: any): void;
}
export class List implements RedomComponent {
el: HTMLElement;
constructor(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any);
update(data: any[], context?: any): void;
onmount?(): void;
onremount?(): void;
onunmount?(): void;
static extend(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): RedomComponentConstructor;
}
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 h(query: RedomQuery, ...args: RedomQueryArgument[]): HTMLElement;
export function el(query: RedomQuery, ...args: RedomQueryArgument[]): HTMLElement;
export function listPool(View: RedomComponentConstructor, key?: string, initData?: any): ListPool;
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 s(query: RedomQuery, ...args: RedomQueryArgument[]): SVGElement;
export function text(str: string): Text;
export namespace list {
function extend(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): RedomComponentConstructor;
}
export namespace svg {
function extend(query: RedomQuery): RedomComponentConstructor;
}

View File

@ -1,39 +0,0 @@
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!'));
class Td implements redom.RedomComponent {
el: HTMLElement;
constructor() {
this.el = redom.h('td');
}
update(value: any) {
this.el.textContent = value;
}
onmount() {
console.log('mounted td');
}
}
const Tr = redom.list.extend('tr', Td);
const table = redom.list('table', Tr);
table.onmount = () => console.log('mounted table');
table.update([
[1, 2],
[3, 4],
]);
redom.mount(document.body, table);

View File

@ -1,25 +0,0 @@
{
"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"
]
}

View File

@ -1 +0,0 @@
{ "extends": "dtslint/dt.json" }