Skip to content

Commit 6fa5f11

Browse files
Paul VarachePaul Varache
authored andcommitted
More types
1 parent f23b2d9 commit 6fa5f11

23 files changed

Lines changed: 214 additions & 197 deletions

File tree

β€Žsrc/@types/flow-down/flow-down.d.tsβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ declare module 'flow-down/flow-down.js' {
88

99
type ProviderMixin = <B extends Constructor<HTMLElement>>(parent : B) => B;
1010

11+
interface IActionEvent {
12+
type : string;
13+
[K : string] : any;
14+
}
15+
1116
interface Store {
1217
StateReceiver : any;
1318
ReceiverBehavior : any;
1419
StateProvider : ProviderMixin;
1520
id : number;
1621
providerElement : HTMLElement;
22+
dispatch(event : IActionEvent) : void;
23+
getState() : any;
24+
addMutator(mutator : (this : any, action : IActionEvent) => void) : void;
25+
appStateComponent : PolymerElement;
1726
}
1827
export function createStore(initialState : object) : Store;
1928
}

β€Žsrc/@types/types.d.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interface Type<T> extends Function { new (...args : any[]) : T; }
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Store from '../store.js';
2+
import FlowDown from 'flow-down/flow-down.js';
23

34
const CONSTANTS = [
45
'LOAD_CHALLENGE',
@@ -21,10 +22,10 @@ const CONSTANTS = [
2122
];
2223
const CHALLENGE_TYPES = Store.types(CONSTANTS);
2324

24-
const BANNER_ICONS = {
25+
const BANNER_ICONS : any= {
2526
default: '/assets/avatar/judoka-face.svg',
2627
};
27-
const ChallengeActions = (store) => {
28+
const ChallengeActions = (store : FlowDown.Store) => {
2829
function getProgress() {
2930
const state = store.getState();
3031
if (!state.steps) {
@@ -169,16 +170,16 @@ const ChallengeActions = (store) => {
169170
});
170171

171172
return {
172-
load(challenge) {
173+
load(challenge : any) {
173174
store.dispatch({ type: CHALLENGE_TYPES.LOAD_CHALLENGE, challenge });
174175
},
175-
loadVariables(variables) {
176+
loadVariables(variables : any[]) {
176177
store.dispatch({ type: CHALLENGE_TYPES.LOAD_VARIABLES, variables });
177178
},
178-
updateStepIndex(index) {
179+
updateStepIndex(index : number) {
179180
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_STEP_INDEX, index });
180181
},
181-
updateSteps(steps) {
182+
updateSteps(steps : any[]) {
182183
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_STEPS, steps });
183184
},
184185
disableBannerButton() {
@@ -187,7 +188,7 @@ const ChallengeActions = (store) => {
187188
enableBannerButton() {
188189
store.dispatch({ type: CHALLENGE_TYPES.ENABLE_BANNER_BUTTON });
189190
},
190-
updateBannerState(banner = {}) {
191+
updateBannerState(banner : any = {}) {
191192
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_BANNER_STATE, state: banner });
192193
},
193194
enableLockdown() {
@@ -196,19 +197,19 @@ const ChallengeActions = (store) => {
196197
disableLockdown() {
197198
store.dispatch({ type: CHALLENGE_TYPES.DISABLE_LOCKDOWN });
198199
},
199-
updateHistoryOptions(canGoBack, canGoForward) {
200+
updateHistoryOptions(canGoBack : boolean, canGoForward : boolean) {
200201
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_HISTORY_OPTIONS, canGoBack, canGoForward });
201202
},
202-
addHistoryRecord(stepIndex, editorState) {
203+
addHistoryRecord(stepIndex : number, editorState : any) {
203204
store.dispatch({ type: CHALLENGE_TYPES.ADD_HISTORY_RECORD, stepIndex, editorState });
204205
},
205206
completeChallenge() {
206207
store.dispatch({ type: CHALLENGE_TYPES.COMPLETE_CHALLENGE });
207208
},
208-
updateBeacon(beacon) {
209+
updateBeacon(beacon : any) {
209210
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_BEACON, beacon });
210211
},
211-
updateTooltips(tooltips) {
212+
updateTooltips(tooltips : any[]) {
212213
store.dispatch({ type: CHALLENGE_TYPES.UPDATE_TOOLTIPS, tooltips });
213214
},
214215
historyBack() {
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Store from '../store.js';
2+
import FlowDown from 'flow-down/flow-down.js';
23

34
const CONSTANTS = [
45
'SET_TOOLBOX',
@@ -9,7 +10,7 @@ const CONSTANTS = [
910
];
1011
const EDITOR_TYPES = Store.types(CONSTANTS);
1112

12-
const EditorActions = (store) => {
13+
const EditorActions = (store : FlowDown.Store) => {
1314
store.addMutator(function modeActions(action) {
1415
switch (action.type) {
1516
case EDITOR_TYPES.LOAD_SOURCE: {
@@ -43,16 +44,16 @@ const EditorActions = (store) => {
4344
});
4445

4546
return {
46-
loadSource(source) {
47+
loadSource(source : string) {
4748
store.dispatch({ type: EDITOR_TYPES.LOAD_SOURCE, source });
4849
},
49-
setToolbox(toolbox) {
50+
setToolbox(toolbox : any) {
5051
store.dispatch({ type: EDITOR_TYPES.SET_TOOLBOX, toolbox });
5152
},
52-
setFlyoutMode(isFlyoutMode) {
53+
setFlyoutMode(isFlyoutMode : boolean) {
5354
store.dispatch({ type: EDITOR_TYPES.SET_FLYOUT_MODE, isFlyoutMode });
5455
},
55-
editBackground(state) {
56+
editBackground(state : boolean) {
5657
store.dispatch({ type: EDITOR_TYPES.EDIT_BACKGROUND, state });
5758
},
5859
};

β€Žsrc/app/lib/actions/mode.jsβ€Ž

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Store from '../store.js';
2+
import FlowDown from 'flow-down/flow-down.js';
23

34
const CONSTANTS = [
45
'UPDATE_PART_LIST',
@@ -10,18 +11,18 @@ const CONSTANTS = [
1011
];
1112
const PARTS_TYPES = Store.types(CONSTANTS);
1213

13-
const PartsActions = (store) => {
14+
const PartsActions = (store : FlowDown.Store) => {
1415
store.addMutator(function partsActions(action) {
1516
switch (action.type) {
1617
case PARTS_TYPES.UPDATE_PART_LIST: {
1718
const mode = this.get('state.mode');
18-
const partsMap = action.parts.reduce((acc, part) => {
19+
const partsMap = action.parts.reduce((acc : any, part : any) => {
1920
acc[part.type] = part;
2021
return acc;
2122
}, {});
2223
this.set('state.partsMap', partsMap);
2324
if (mode) {
24-
const parts = action.parts.filter(part => mode.parts.indexOf(part.type) !== -1);
25+
const parts = action.parts.filter((part : any) => mode.parts.indexOf(part.type) !== -1);
2526
this.set('state.parts', parts);
2627
}
2728
break;
@@ -61,22 +62,22 @@ const PartsActions = (store) => {
6162
});
6263

6364
return {
64-
updatePartsList(parts) {
65+
updatePartsList(parts : any[]) {
6566
store.dispatch({ type: PARTS_TYPES.UPDATE_PART_LIST, parts });
6667
},
67-
addPart(part) {
68+
addPart(part : any) {
6869
store.dispatch({ type: PARTS_TYPES.ADD_PART, part });
6970
},
70-
removePart(part) {
71+
removePart(part : any) {
7172
store.dispatch({ type: PARTS_TYPES.REMOVE_PART, part });
7273
},
73-
loadAddedParts(part) {
74+
loadAddedParts(part : any) {
7475
store.dispatch({ type: PARTS_TYPES.LOAD_ADDED_PARTS, part });
7576
},
76-
select(index) {
77+
select(index : number) {
7778
store.dispatch({ type: PARTS_TYPES.SELECT, index });
7879
},
79-
updatePart(property, value) {
80+
updatePart(property : string, value : any) {
8081
store.dispatch({ type: PARTS_TYPES.UPDATE, property, value });
8182
},
8283
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { AppModule } from './app-module.js';
22

33
export class GlobalModule extends AppModule {
4-
constructor(output) {
4+
private _listeners : { [K : string] : Function[] } = {};
5+
constructor(output : any) {
56
super(output);
67
this.addMethod('when', '_when');
78
this.addMethod('emit', '_emit');
@@ -13,12 +14,12 @@ export class GlobalModule extends AppModule {
1314

1415
static get id() { return 'global'; }
1516

16-
_when(name, callback) {
17+
_when(name : string, callback : Function) {
1718
this._listeners[name] = this._listeners[name] || [];
1819
this._listeners[name].push(callback);
1920
}
2021

21-
_emit(name, data) {
22+
_emit(name : string, data? : any) {
2223
const listeners = this._listeners[name];
2324
if (!listeners || !Array.isArray(listeners)) {
2425
return;
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import AppModules from './app-modules.js';
2+
import AppModule from './app-module.js';
3+
4+
type IAppModuleType = Type<AppModule> & {
5+
id? : string;
6+
}
27

38
class AppModulesLoader {
4-
constructor(output, modules) {
9+
private output : any;
10+
public appModules : AppModules;
11+
private modules : IAppModuleType[];
12+
constructor(output : any, modules : IAppModuleType[]) {
513
this.output = output;
614
this.appModules = new AppModules(output);
715
this.modules = modules;
816
}
917
start() {
1018
this.appModules.init(this.output.config);
1119
this.modules.forEach((Mod) => {
12-
this.appModules.define(Mod.id, Mod);
20+
if (Mod.id) {
21+
this.appModules.define(Mod.id, Mod);
22+
}
1323
});
1424
}
1525
dispose() {
1626
this.appModules.dispose();
17-
this.modules = null;
1827
}
1928
}
2029

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { AppModule } from './app-module.js';
22

33
export class LoopModule extends AppModule {
4-
constructor() {
5-
super();
4+
private intervals : number[];
5+
constructor(output : any) {
6+
super(output);
67
this.intervals = [];
78

89
this.addMethod('forever', '_forever');
@@ -12,7 +13,7 @@ export class LoopModule extends AppModule {
1213

1314
static get id() { return 'loop'; }
1415

15-
_forever(callback) {
16+
_forever(callback : Function) {
1617
// push the next tick to the end of the events queue
1718
const id = setInterval(callback, 10);
1819
this.intervals.push(id);

0 commit comments

Comments
Β (0)