From 328a83158ea694e005f94f8af722e6ec84e3f26d Mon Sep 17 00:00:00 2001 From: Yuichi Murata Date: Sun, 15 Feb 2015 23:21:20 +0900 Subject: [PATCH 1/2] Added eventemitter3/eventemitter3.d.ts(0.1.6). --- eventemitter3/eventemitter3-test.ts | 65 ++++++++++++++++++ eventemitter3/eventemitter3.d.ts | 100 ++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 eventemitter3/eventemitter3-test.ts create mode 100644 eventemitter3/eventemitter3.d.ts diff --git a/eventemitter3/eventemitter3-test.ts b/eventemitter3/eventemitter3-test.ts new file mode 100644 index 000000000..05138ab34 --- /dev/null +++ b/eventemitter3/eventemitter3-test.ts @@ -0,0 +1,65 @@ +/// +'use strict'; + +import EventEmitter = require('eventemitter3'); + +class EventEmitterTest { + v: EventEmitter; + + constructor() { + this.v = new EventEmitter(); + this.v = new EventEmitter.EventEmitter(); + this.v = new EventEmitter.EventEmitter2(); + this.v = new EventEmitter.EventEmitter3(); + } + + listeners() { + var v1: Function[] = this.v.listeners('click'); + } + + emit() { + var v1: boolean = this.v.emit('click'); + var v2: boolean = this.v.emit('click', 1); + var v3: boolean = this.v.emit('click', 1, '1'); + var v4: boolean = this.v.emit('click', 1, '1', true); + var v5: boolean = this.v.emit('click', 1, '1', true, new Date()); + } + + on() { + var fn = () => console.log(1); + var v1: EventEmitter = this.v.on('click', fn); + var v2: EventEmitter = this.v.on('click', fn, this); + } + + once() { + var fn = () => console.log(1); + var v1: EventEmitter = this.v.once('click', fn); + var v2: EventEmitter = this.v.once('click', fn, this); + } + + removeListener() { + var fn = () => console.log(1); + var v1: EventEmitter = this.v.removeListener('click', fn); + var v2: EventEmitter = this.v.removeListener('click', fn, true); + } + + removeAllListeners() { + var v1: EventEmitter = this.v.removeAllListeners('click'); + } + + off() { + var fn = () => console.log(1); + var v1: EventEmitter = this.v.off('click', fn); + var v2: EventEmitter = this.v.off('click', fn, true); + } + + addListener() { + var fn = () => console.log(1); + var v1: EventEmitter = this.v.addListener('click', fn); + var v2: EventEmitter = this.v.addListener('click', fn, this); + } + + setMaxListeners() { + var v1: EventEmitter = this.v.setMaxListeners(); + } +} diff --git a/eventemitter3/eventemitter3.d.ts b/eventemitter3/eventemitter3.d.ts new file mode 100644 index 000000000..60f6e6e93 --- /dev/null +++ b/eventemitter3/eventemitter3.d.ts @@ -0,0 +1,100 @@ +// Type definitions for EventEmitter3 0.1.6 +// Project: https://github.com/primus/eventemitter3 +// Definitions by: Yuichi Murata +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module EventEmitter3 { + export class EventEmitter { + /** + * Minimal EventEmitter interface that is molded against the Node.js + * EventEmitter interface. + * + * @constructor + * @api public + */ + constructor(); + + /** + * Return a list of assigned event listeners. + * + * @param {String} event The events that should be listed. + * @returns {Array} + * @api public + */ + listeners(event: string): Function[]; + + /** + * Emit an event to all registered event listeners. + * + * @param {String} event The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public + */ + emit(event: string, ...args: any[]): boolean; + + /** + * Register a new EventListener for the given event. + * + * @param {String} event Name of the event. + * @param {Functon} fn Callback function. + * @param {Mixed} context The context of the function. + * @api public + */ + on(event: string, fn: Function, context?: any): EventEmitter; + + /** + * Add an EventListener that's only called once. + * + * @param {String} event Name of the event. + * @param {Function} fn Callback function. + * @param {Mixed} context The context of the function. + * @api public + */ + once(event: string, fn: Function, context?: any): EventEmitter; + + /** + * Remove event listeners. + * + * @param {String} event The event we want to remove. + * @param {Function} fn The listener that we need to find. + * @param {Boolean} once Only remove once listeners. + * @api public + */ + removeListener(event: string, fn: Function, once?: boolean): EventEmitter; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param {String} event The event want to remove all listeners for. + * @api public + */ + removeAllListeners(event: string): EventEmitter; + + // + // Alias methods names because people roll like that. + // + off(event: string, fn: Function, once?: boolean): EventEmitter; + addListener(event: string, fn: Function, context?: any): EventEmitter; + + // + // This function doesn't apply anymore. + // + setMaxListeners(): EventEmitter; + } + export module EventEmitter { + // + // Expose the module. + // + export class EventEmitter extends EventEmitter3.EventEmitter {} + export class EventEmitter2 extends EventEmitter3.EventEmitter {} + export class EventEmitter3 extends EventEmitter3.EventEmitter {} + } +} + +declare module 'eventemitter3' { + // + // Expose the module. + // + class EventEmitter extends EventEmitter3.EventEmitter {} + export = EventEmitter; +} From aebec5e86de91eca0bf6e4ca7426146bf5fa6e97 Mon Sep 17 00:00:00 2001 From: Yuichi Murata Date: Wed, 18 Feb 2015 19:14:29 +0900 Subject: [PATCH 2/2] Added fluxxor/fluxxor.d.ts(1.5.2). --- fluxxor/fluxxor-test.ts | 164 ++++++++++++++++++++++++++++++++++++++++ fluxxor/fluxxor.d.ts | 70 +++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 fluxxor/fluxxor-test.ts create mode 100644 fluxxor/fluxxor.d.ts diff --git a/fluxxor/fluxxor-test.ts b/fluxxor/fluxxor-test.ts new file mode 100644 index 000000000..87e978248 --- /dev/null +++ b/fluxxor/fluxxor-test.ts @@ -0,0 +1,164 @@ +/// + +import React = require('react'); +import Fluxxor = require('fluxxor'); + +class DispatcherTest { + v: Fluxxor.Dispatcher; + + constructor() { + var stores: Fluxxor.Store[]; + this.v = new Fluxxor.Dispatcher(stores); + } + + addStore() { + var store: Fluxxor.Store; + var v1: void = this.v.addStore('mystore', store); + } + + dispatch() { + var fn = () => console.log(1); + var v1: void = this.v.dispatch(fn); + } + + doDispatchLoop() { + var fn = () => console.log(1); + var v1: void = this.v.doDispatchLoop(fn); + } + + waitForStores() { + var store: Fluxxor.Store; + var fn = () => console.log(1); + var v1: void = this.v.waitForStores(store, ['mystore1', 'mystore2'], fn); + } +} + +class FluxTest { + v: Fluxxor.Flux; + + constructor() { + var stores: any; + var actions: any; + this.v = new Fluxxor.Flux(stores, actions); + } + + props() { + var stores: any = this.v.stores; + var actions: any = this.v.actions; + } + + addActions() { + var actions: any; + var v1: void = this.v.addActions(actions); + } + + addAction() { + var fn = () => console.log(1); + + // first form + var v1: void = this.v.addAction('action1', fn); + var v2: void = this.v.addAction('action1', 'action2', fn); + + // second form + var v3: void = this.v.addAction(['action1'], fn); + var v4: void = this.v.addAction(['action1','action2'], fn); + } + + store() { + var store1: any = this.v.store('mystore'); + } + + addStore() { + var store: Fluxxor.Store; + var v1: void = this.v.addStore('mystore', store); + } + + addStores() { + var stores: any; + var v1: void = this.v.addStores(stores); + } +} + +class StoreTest { + v: Fluxxor.Store; + + bindActions() { + var fn = () => console.log(1); + + // first form + var v1: void = this.v.bindActions('action1', fn); + var v2: void = this.v.bindActions( + 'action1', fn, + 'action2', fn + ); + + // second form + var v3: void = this.v.bindActions([ + 'action1', fn, + 'action2', fn, + ]); + } + + waitFor() { + var fn = () => console.log(1); + var v1: void = this.v.waitFor(['mystore1','mystore2'], fn); + } +} + +class ContextTest { + v: Fluxxor.Context; + + props() { + var v1: Fluxxor.Flux = this.v.flux; + } +} + +class FluxMixinTest { + v: Fluxxor.FluxMixin; + + constructor() { + this.v = Fluxxor.FluxMixin(React); + } + + getFlux() { + var v1: Fluxxor.Flux = this.v.getFlux(); + } +} + +class FluxChildMixinTest { + v: Fluxxor.FluxChildMixin; + + constructor() { + this.v = Fluxxor.FluxChildMixin(React); + } + + getFlux() { + var v1: Fluxxor.Flux = this.v.getFlux(); + } +} + +class StoreWatchMixinTest { + v: Fluxxor.StoreWatchMixin; + + constructor() { + this.v = Fluxxor.StoreWatchMixin('store1'); + this.v = Fluxxor.StoreWatchMixin('store1','store2'); + this.v = Fluxxor.StoreWatchMixin('store1','store2','store3'); + } + + getStateFromFlux() { + var v1: StoreState = this.v.getStateFromFlux(); + } +} +new StoreWatchMixinTest(); +new StoreWatchMixinTest<{ a: Fluxxor.Store; }>(); +new StoreWatchMixinTest<{ b: Fluxxor.Store; }>(); + +function createStoreTest() { + var spec: Fluxxor.StoreSpec; + var Class: Fluxxor.StoreClass = Fluxxor.createStore(spec); + var store1: any = new Class(); + var store2: any = new Class({value: 1}); +} + +var versionTest: string = Fluxxor.version; diff --git a/fluxxor/fluxxor.d.ts b/fluxxor/fluxxor.d.ts new file mode 100644 index 000000000..e857a6b15 --- /dev/null +++ b/fluxxor/fluxxor.d.ts @@ -0,0 +1,70 @@ +// Type definitions for Fluxxor 1.5.2 +// Project: https://github.com/BinaryMuse/fluxxor +// Definitions by: Yuichi Murata +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module Fluxxor { + class Dispatcher { + constructor(stores: any); + addStore(name: string, store: Store): void; + dispatch(action: Function): void; + doDispatchLoop(action: Function): void; + waitForStores(store: Store, stores: string[], fn: Function): void; + } + + class Flux extends EventEmitter3.EventEmitter { + constructor(stores: any, actions: any); + addActions(actions: any): void; + addAction(...args: Array): void; + addAction(names: string[], action: Function): void; + store(name: string): any; + addStore(name: string, store: Store): void; + addStores(stores: any): void; + stores: any; + actions: any; + } + + interface Store extends EventEmitter3.EventEmitter { + bindActions(...args: Array): void; + bindActions(args: Array): void; + waitFor(stores: string[], fn: Function): void; + } + + interface StoreSpec { + initialize?(instance?: any, options?: {}): void; + actions?: any; + } + + interface StoreClass { + new (options?: {}): any; + } + + interface Context { + flux: Flux; + } + + interface FluxMixin { + getFlux(): Flux; + } + + interface FluxChildMixin { + getFlux(): Flux; + } + + interface StoreWatchMixin { + getStateFromFlux(): StoreState; + } + + function FluxMixin(React: React.Exports): FluxMixin; + function FluxChildMixin(React: React.Exports): FluxChildMixin; + function StoreWatchMixin(...storeNames: string[]): StoreWatchMixin; + function createStore(spec: StoreSpec): StoreClass; + var version: string; +} + +declare module 'fluxxor' { + export = Fluxxor; +}