From 48dbfc2eebfc5353a9c3a83e7788530621d8926e Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sat, 17 Oct 2015 16:21:08 +0200 Subject: [PATCH 1/4] Added RefluxJS typings --- reflux/reflux.d.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 reflux/reflux.d.ts diff --git a/reflux/reflux.d.ts b/reflux/reflux.d.ts new file mode 100644 index 000000000..335f268ca --- /dev/null +++ b/reflux/reflux.d.ts @@ -0,0 +1,57 @@ +// Type definitions for RefluxJS +// Project: https://github.com/reflux/refluxjs +// Definitions by: Maurice de Beijer +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module RefluxCore { + + interface StoreDefinition { + listenables?: any[], + init?: Function, + getInitialState?: Function, + [propertyName: string]: any; + } + + interface ListenFn { + (...params: any[]):any, + completed: Function, + failed: Function + } + interface Listenable { + listen: ListenFn + } + + interface Subscription { + stop: Function, + listenable: Listenable + } + + interface Store { + hasListener(listenable: Listenable): boolean, + listenToMany(listenables: Listenable[]): void, + validateListening(listenable: Listenable): string, + listenTo(listenable: Listenable, callback: Function, defaultCallback?: Function): Subscription, + stopListeningTo(listenable: Listenable): boolean, + stopListeningToAll(): void, + fetchInitialState(listenable: Listenable, defaultCallback: Function): void, + trigger(state: any) + } + + interface ActionsDefinition { + [index: string]:any + } + + interface Actions { + [index: string]: Listenable + } + + function createStore(definition: StoreDefinition): Store; + + function createActions(definition: ActionsDefinition): any; + function createActions(definitions: string[]): any; +} + +declare module "reflux" { + export = RefluxCore; +} + From 476caae5ae10e27fc6aa1b004c81c3615fb8f028 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sat, 17 Oct 2015 16:40:05 +0200 Subject: [PATCH 2/4] Added test --- reflux/reflux-tests.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 reflux/reflux-tests.ts diff --git a/reflux/reflux-tests.ts b/reflux/reflux-tests.ts new file mode 100644 index 000000000..ce4a2920c --- /dev/null +++ b/reflux/reflux-tests.ts @@ -0,0 +1,39 @@ +/// + + +var Reflux: RefluxCore; + +var syncActions = Reflux.createActions([ + "statusUpdate", + "statusEdited", + "statusAdded" +]); + + +var asyncActions = Reflux.createActions({ + fireBall: {asyncResult: true} +}); + +asyncActions.fireBall.listen(function () { + // Trigger async action + setTimeout(() => this.completed(true), 1000); +}); + + +// Creates a DataStore +var statusStore = Reflux.createStore({ + + // Initial setup + init: function () { + + // Register statusUpdate action + this.listenTo(asyncActions.fireBall, this.onFireBall); + }, + // Callback + onFireBall: function (flag) { + var status = flag ? 'ONLINE' : 'OFFLINE'; + + // Pass on to listeners + this.trigger(status); + } +}); From e5109ed2914ea913ae8255a8977a713c68a74841 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sat, 17 Oct 2015 21:09:18 +0200 Subject: [PATCH 3/4] Added functionality --- reflux/reflux-tests.ts | 26 +++++++++++++++++++++++--- reflux/reflux.d.ts | 5 +++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/reflux/reflux-tests.ts b/reflux/reflux-tests.ts index ce4a2920c..3ebc6f2a1 100644 --- a/reflux/reflux-tests.ts +++ b/reflux/reflux-tests.ts @@ -1,7 +1,8 @@ -/// +import Reflux = require("reflux"); +import React = require("react"); - -var Reflux: RefluxCore; +//var Reflux: RefluxCore; +//var React: React; var syncActions = Reflux.createActions([ "statusUpdate", @@ -37,3 +38,22 @@ var statusStore = Reflux.createStore({ this.trigger(status); } }); + +Reflux.createAction({ + children: ["progressed", "completed", "failed"] +}); + + +var actions = Reflux.createActions(["fireBall", "magicMissile"]); + +var Store = Reflux.createStore({ + init: function () { + this.listenToMany(actions); + }, + onFireBall: function () { + // whoooosh! + }, + onMagicMissile: function () { + // bzzzzapp! + } +}); diff --git a/reflux/reflux.d.ts b/reflux/reflux.d.ts index 335f268ca..70757b9d0 100644 --- a/reflux/reflux.d.ts +++ b/reflux/reflux.d.ts @@ -47,8 +47,13 @@ declare module RefluxCore { function createStore(definition: StoreDefinition): Store; + function createAction(definition: ActionsDefinition): any; + function createActions(definition: ActionsDefinition): any; function createActions(definitions: string[]): any; + + function listenTo(store: Store, handler: string); + function setState(state: any); } declare module "reflux" { From 1a105463c5354f425f5f70ec755dfe317dcba2c5 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sat, 17 Oct 2015 21:15:47 +0200 Subject: [PATCH 4/4] Fixed test errors --- reflux/reflux-tests.ts | 8 ++++---- reflux/reflux.d.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reflux/reflux-tests.ts b/reflux/reflux-tests.ts index 3ebc6f2a1..afebd1a81 100644 --- a/reflux/reflux-tests.ts +++ b/reflux/reflux-tests.ts @@ -1,9 +1,9 @@ +/// +/// + import Reflux = require("reflux"); import React = require("react"); -//var Reflux: RefluxCore; -//var React: React; - var syncActions = Reflux.createActions([ "statusUpdate", "statusEdited", @@ -31,7 +31,7 @@ var statusStore = Reflux.createStore({ this.listenTo(asyncActions.fireBall, this.onFireBall); }, // Callback - onFireBall: function (flag) { + onFireBall: function (flag: boolean) { var status = flag ? 'ONLINE' : 'OFFLINE'; // Pass on to listeners diff --git a/reflux/reflux.d.ts b/reflux/reflux.d.ts index 70757b9d0..035bca7f3 100644 --- a/reflux/reflux.d.ts +++ b/reflux/reflux.d.ts @@ -34,7 +34,7 @@ declare module RefluxCore { stopListeningTo(listenable: Listenable): boolean, stopListeningToAll(): void, fetchInitialState(listenable: Listenable, defaultCallback: Function): void, - trigger(state: any) + trigger(state: any):void; } interface ActionsDefinition { @@ -52,8 +52,8 @@ declare module RefluxCore { function createActions(definition: ActionsDefinition): any; function createActions(definitions: string[]): any; - function listenTo(store: Store, handler: string); - function setState(state: any); + function listenTo(store: Store, handler: string):void; + function setState(state: any):void; } declare module "reflux" {