mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 03:02:04 +08:00
Cytoscape: fixed events list, fixed interfaces inheritance (+1 squashed commits)
Squashed commits: [d48a8821f3] tmp
This commit is contained in:
@@ -2,14 +2,8 @@
|
||||
|
||||
// TODO: document all aliases as aliases, not as duplicates!
|
||||
|
||||
const assert = (tag: boolean) => { if (!tag) throw new Error(); };
|
||||
const aliases = (...obj: Array<{}>) => { if (obj.slice(1).some((alias) => alias !== obj[0])) throw new Error(); };
|
||||
const events = (obj: any) => {
|
||||
aliases(obj.on, obj.bind, obj.listen, obj.addListener);
|
||||
aliases(obj.promiseOn, obj.pon);
|
||||
aliases(obj.off, obj.unbind, obj.unlisten, obj.removeListener);
|
||||
aliases(obj.emit, obj.trigger);
|
||||
};
|
||||
const assert = (tag: boolean) => {};
|
||||
const aliases = (...obj: Array<{}>) => {};
|
||||
|
||||
// definitions
|
||||
function oneOf<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E): A | B | C | D | E;
|
||||
@@ -129,7 +123,7 @@ cy.on('zoom', (event) => {
|
||||
}
|
||||
});
|
||||
cy.off('zoom');
|
||||
events(cy);
|
||||
// events(cy); - TODO
|
||||
|
||||
cy.add({ data: { id: 'g' }, position: {x: 200, y: 150} });
|
||||
cy.add([
|
||||
@@ -383,11 +377,18 @@ assert(eles.removed());
|
||||
assert(!eles.inside());
|
||||
eles.restore();
|
||||
|
||||
([ele, eles, node, nodes, edge, edges] as cytoscape.CollectionReturnValue[]).forEach((elem) => {
|
||||
aliases(elem.clone, elem.copy);
|
||||
events(elem);
|
||||
aliases(elem.data, elem.attr);
|
||||
aliases(elem.removeData, elem.removeAttr);
|
||||
([ele, eles, node, nodes, edge, edges] as [
|
||||
cytoscape.SingularElementReturnValue,
|
||||
cytoscape.CollectionReturnValue,
|
||||
cytoscape.NodeSingular,
|
||||
cytoscape.NodeCollection,
|
||||
cytoscape.EdgeSingular,
|
||||
cytoscape.EdgeCollection
|
||||
]).forEach((elemType) => {
|
||||
aliases(elemType.clone, elemType.copy);
|
||||
// events(elemType); - TODO
|
||||
aliases(elemType.data, elemType.attr);
|
||||
aliases(elemType.removeData, elemType.removeAttr);
|
||||
});
|
||||
// TODO: tests for data flow
|
||||
|
||||
@@ -490,6 +491,6 @@ eles.reduce<any[]>((prev, ele, i, eles) => [...prev, [ele, i]], []).concat(['fin
|
||||
const min = eles.min((ele, i, eles) => ele.id.length + i); min.ele.scratch('min', min.value);
|
||||
const max = eles.max((ele, i, eles) => ele.id.length + i); max.ele.scratch('max', max.value);
|
||||
|
||||
// TODO: traversing (need to actively check the nodes/edeges distinction)
|
||||
// TODO: traversing (need to actively check the nodes/edges distinction)
|
||||
// TODO: algorithms
|
||||
// TODO: compound nodes (there aren't any in current test case)
|
||||
|
||||
27
types/cytoscape/index.d.ts
vendored
27
types/cytoscape/index.d.ts
vendored
@@ -1118,7 +1118,7 @@ declare namespace cytoscape {
|
||||
* http://js.cytoscape.org/#collection
|
||||
*/
|
||||
interface Collection<TOut = SingularElementReturnValue, TIn = SingularElementArgument>
|
||||
extends Singular,
|
||||
extends
|
||||
CollectionGraphManipulation, CollectionEvents,
|
||||
CollectionData, CollectionPosition,
|
||||
CollectionLayout,
|
||||
@@ -1129,8 +1129,10 @@ declare namespace cytoscape {
|
||||
/**
|
||||
* ele --> Cy.Singular
|
||||
* a collection of a single element (node or edge)
|
||||
* NB: every singular collection is a general collection too (but not vice versa)!
|
||||
*/
|
||||
interface Singular extends
|
||||
interface Singular<TOut = SingularElementReturnValue, TIn = SingularElementArgument>
|
||||
extends Collection<TOut, TIn>,
|
||||
SingularGraphManipulation,
|
||||
SingularData, SingularPosition,
|
||||
SingularSelection, SingularStyle, SingularAnimation { }
|
||||
@@ -1154,7 +1156,7 @@ declare namespace cytoscape {
|
||||
*
|
||||
* The output is a collection of edge elements OR single edge.
|
||||
*/
|
||||
interface EdgeCollection extends Collection<EdgeSingular, EdgeSingular>, EdgeSingular,
|
||||
interface EdgeCollection extends EdgeSingular,
|
||||
EdgeCollectionTraversing { }
|
||||
/**
|
||||
* nodes -> Cy.NodeCollection
|
||||
@@ -1162,7 +1164,7 @@ declare namespace cytoscape {
|
||||
*
|
||||
* The output is a collection of node elements OR single node.
|
||||
*/
|
||||
interface NodeCollection extends Collection<NodeSingular, NodeSingular>, NodeSingular,
|
||||
interface NodeCollection extends NodeSingular,
|
||||
NodeCollectionMetadata, NodeCollectionPosition, NodeCollectionTraversing,
|
||||
NodeCollectionCompound { }
|
||||
|
||||
@@ -1172,14 +1174,14 @@ declare namespace cytoscape {
|
||||
* edge --> Cy.EdgeSingular
|
||||
* a collection of a single edge
|
||||
*/
|
||||
interface EdgeSingular extends Singular,
|
||||
interface EdgeSingular extends Singular<EdgeSingular, EdgeSingular>,
|
||||
EdgeSingularData, EdgeSingularPoints, EdgeSingularTraversing { }
|
||||
|
||||
/**
|
||||
* node --> Cy.NodeSingular
|
||||
* a collection of a single node
|
||||
*/
|
||||
interface NodeSingular extends Singular,
|
||||
interface NodeSingular extends Singular<NodeSingular, NodeSingular>,
|
||||
NodeSingularMetadata, NodeSingularPosition, NodeSingularCompound { }
|
||||
|
||||
/**
|
||||
@@ -1251,6 +1253,15 @@ declare namespace cytoscape {
|
||||
on(events: EventNames, selector: string, data: any, handler: EventHandler): void;
|
||||
on(events: EventNames, selector: string, handler: EventHandler): void;
|
||||
on(events: EventNames, handler: EventHandler): void;
|
||||
bind(events: EventNames, selector: string, data: any, handler: EventHandler): void;
|
||||
bind(events: EventNames, selector: string, handler: EventHandler): void;
|
||||
bind(events: EventNames, handler: EventHandler): void;
|
||||
listen(events: EventNames, selector: string, data: any, handler: EventHandler): void;
|
||||
listen(events: EventNames, selector: string, handler: EventHandler): void;
|
||||
listen(events: EventNames, handler: EventHandler): void;
|
||||
addListener(events: EventNames, selector: string, data: any, handler: EventHandler): void;
|
||||
addListener(events: EventNames, selector: string, handler: EventHandler): void;
|
||||
addListener(events: EventNames, handler: EventHandler): void;
|
||||
/**
|
||||
* http://js.cytoscape.org/#eles.promiseOn
|
||||
* alias: pon
|
||||
@@ -1280,11 +1291,15 @@ declare namespace cytoscape {
|
||||
* alias unbind, unlisten, removeListener
|
||||
*/
|
||||
off(events: EventNames, selector?: string, handler?: EventHandler): void;
|
||||
unbind(events: EventNames, selector?: string, handler?: EventHandler): void;
|
||||
unlisten(events: EventNames, selector?: string, handler?: EventHandler): void;
|
||||
removeListener(events: EventNames, selector?: string, handler?: EventHandler): void;
|
||||
/**
|
||||
* http://js.cytoscape.org/#eles.trigger
|
||||
* alias: emit
|
||||
*/
|
||||
trigger(events: EventNames, extra?: string[]): void;
|
||||
emit(events: EventNames, extra?: string[]): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user