-
Notifications
You must be signed in to change notification settings - Fork 17
/
router.js
54 lines (48 loc) · 1.3 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var routers = {}, activeRouter = 'default';
var defaultConfig = {
go: function(name, stepId) {},
getParams: function(stepId) {},
getStep: function() {},
path: function(name, stepId) {
return '#' + stepId;
}
};
Wizard.Router = {
apply: function(method, args) {
var router = routers[activeRouter];
return router[method].apply(router, args);
},
go: function() {
return this.apply('go', arguments);
},
getParams: function() {
return this.apply('getParams', arguments);
},
getStep: function() {
return this.apply('getStep', arguments);
},
path: function() {
return this.apply('path', arguments);
}
};
Wizard.registerRouter = function wizardRegisterRouter(name, config) {
if (routers[name]) {
throw new Meteor.Error('router-configured', 'A router with his name has already been configured.');
}
routers[name] = _.defaults(config, defaultConfig);
};
Wizard.useRouter = function wizardUseRouter(name) {
if (!routers[name]) {
throw new Meteor.Error('router-not-configured', 'A router with this name hasn\'t been configured.');
}
activeRouter = name;
};
Wizard.registerRouter('default', {
activeStep: new ReactiveVar(),
go: function(name, stepId) {
this.activeStep.set(stepId);
},
getStep: function() {
return this.activeStep.get();
}
});