forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#6336 from mauricedb/Add_reflux
Add RefluxJS
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// <reference path="reflux.d.ts" /> | ||
/// <reference path="../react/react.d.ts" /> | ||
|
||
import Reflux = require("reflux"); | ||
import React = require("react"); | ||
|
||
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: boolean) { | ||
var status = flag ? 'ONLINE' : 'OFFLINE'; | ||
|
||
// Pass on to listeners | ||
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! | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Type definitions for RefluxJS | ||
// Project: https://github.com/reflux/refluxjs | ||
// Definitions by: Maurice de Beijer <https://github.com/mauricedb> | ||
// 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):void; | ||
} | ||
|
||
interface ActionsDefinition { | ||
[index: string]:any | ||
} | ||
|
||
interface Actions { | ||
[index: string]: Listenable | ||
} | ||
|
||
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):void; | ||
function setState(state: any):void; | ||
} | ||
|
||
declare module "reflux" { | ||
export = RefluxCore; | ||
} | ||
|