Merge pull request #485 from snabbdom/eslint-typescript-array-type

style: @typescript-eslint/array-type
pull/489/head
Simon Friis Vindum 5 years ago committed by GitHub
commit 5a3ae5e14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,6 @@ module.exports = {
extends: 'standard-with-typescript',
parserOptions: { project: [ './tsconfig.json', ] },
rules: {
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/brace-style': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',

@ -1,5 +1,5 @@
import {vnode, VNode, VNodeData} from './vnode';
export type VNodes = Array<VNode>;
export type VNodes = VNode[];
export type VNodeChildElement = VNode | string | number | undefined | null;
export type ArrayOrElement<T> = T | T[];
export type VNodeChildren = ArrayOrElement<VNodeChildElement>

@ -73,7 +73,7 @@ function applyRemoveStyle(vnode: VNode, rm: () => void): void {
reflowForced = true;
}
var name: string, elm = vnode.elm, i = 0, compStyle: CSSStyleDeclaration,
style = s.remove, amount = 0, applied: Array<string> = [];
style = s.remove, amount = 0, applied: string[] = [];
for (name in style) {
applied.push(name);
(elm as any).style[name] = style[name];

@ -8,7 +8,7 @@ import htmlDomApi, {DOMAPI} from './htmldomapi';
function isUndef(s: any): boolean { return s === undefined; }
function isDef(s: any): boolean { return s !== undefined; }
type VNodeQueue = Array<VNode>;
type VNodeQueue = VNode[];
const emptyNode = vnode('', {}, [], undefined, undefined);
@ -23,12 +23,12 @@ function isVnode(vnode: any): vnode is VNode {
type KeyToIndexMap = {[key: string]: number};
type ArraysOf<T> = {
[K in keyof T]: (T[K])[];
[K in keyof T]: Array<T[K]>;
}
type ModuleHooks = ArraysOf<Module>;
function createKeyToOldIdx(children: Array<VNode>, beginIdx: number, endIdx: number): KeyToIndexMap {
function createKeyToOldIdx(children: VNode[], beginIdx: number, endIdx: number): KeyToIndexMap {
let i: number, map: KeyToIndexMap = {}, key: Key | undefined, ch;
for (i = beginIdx; i <= endIdx; ++i) {
ch = children[i];
@ -40,7 +40,7 @@ function createKeyToOldIdx(children: Array<VNode>, beginIdx: number, endIdx: num
return map;
}
const hooks: (keyof Module)[] = ['create', 'update', 'remove', 'destroy', 'pre', 'post'];
const hooks: Array<keyof Module> = ['create', 'update', 'remove', 'destroy', 'pre', 'post'];
export {h} from './h';
export {thunk} from './thunk';
@ -55,7 +55,7 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
for (j = 0; j < modules.length; ++j) {
const hook = modules[j][hooks[i]];
if (hook !== undefined) {
(cbs[hooks[i]] as Array<any>).push(hook);
(cbs[hooks[i]] as any[]).push(hook);
}
}
}
@ -126,7 +126,7 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
function addVnodes(
parentElm: Node,
before: Node | null,
vnodes: Array<VNode>,
vnodes: VNode[],
startIdx: number,
endIdx: number,
insertedVnodeQueue: VNodeQueue
@ -156,7 +156,7 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
}
function removeVnodes(parentElm: Node,
vnodes: Array<VNode>,
vnodes: VNode[],
startIdx: number,
endIdx: number): void {
for (; startIdx <= endIdx; ++startIdx) {
@ -180,8 +180,8 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
}
function updateChildren(parentElm: Node,
oldCh: Array<VNode>,
newCh: Array<VNode>,
oldCh: VNode[],
newCh: VNode[],
insertedVnodeQueue: VNodeQueue) {
let oldStartIdx = 0, newStartIdx = 0;
let oldEndIdx = oldCh.length - 1;
@ -269,18 +269,18 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
}
if (isUndef(vnode.text)) {
if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(elm, oldCh as Array<VNode>, ch as Array<VNode>, insertedVnodeQueue);
if (oldCh !== ch) updateChildren(elm, oldCh as VNode[], ch as VNode[], insertedVnodeQueue);
} else if (isDef(ch)) {
if (isDef(oldVnode.text)) api.setTextContent(elm, '');
addVnodes(elm, null, ch as Array<VNode>, 0, (ch as Array<VNode>).length - 1, insertedVnodeQueue);
addVnodes(elm, null, ch as VNode[], 0, (ch as VNode[]).length - 1, insertedVnodeQueue);
} else if (isDef(oldCh)) {
removeVnodes(elm, oldCh as Array<VNode>, 0, (oldCh as Array<VNode>).length - 1);
removeVnodes(elm, oldCh as VNode[], 0, (oldCh as VNode[]).length - 1);
} else if (isDef(oldVnode.text)) {
api.setTextContent(elm, '');
}
} else if (oldVnode.text !== vnode.text) {
if (isDef(oldCh)) {
removeVnodes(elm, oldCh as Array<VNode>, 0, (oldCh as Array<VNode>).length - 1);
removeVnodes(elm, oldCh as VNode[], 0, (oldCh as VNode[]).length - 1);
}
api.setTextContent(elm, vnode.text as string);
}

@ -3,7 +3,7 @@ import {h} from './h';
export interface ThunkData extends VNodeData {
fn: () => VNode;
args: Array<any>;
args: any[];
}
export interface Thunk extends VNode {
@ -11,8 +11,8 @@ export interface Thunk extends VNode {
}
export interface ThunkFn {
(sel: string, fn: Function, args: Array<any>): Thunk;
(sel: string, key: any, fn: Function, args: Array<any>): Thunk;
(sel: string, fn: Function, args: any[]): Thunk;
(sel: string, key: any, fn: Function, args: any[]): Thunk;
}
function copyToThunk(vnode: VNode, thunk: VNode): void {

@ -10,7 +10,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
const c = cn ? '.' + cn.split(' ').join('.') : '';
const sel = api.tagName(node).toLowerCase() + id + c;
const attrs: any = {};
const children: Array<VNode> = [];
const children: VNode[] = [];
let name: string;
let i: number, n: number;
const elmAttrs = node.attributes;

@ -32,7 +32,7 @@ export interface VNodeData {
key?: Key;
ns?: string; // for SVGs
fn?: () => VNode; // for thunks
args?: Array<any>; // for thunks
args?: any[]; // for thunks
[key: string]: any; // for any other 3rd party module
}

Loading…
Cancel
Save