This repository has been archived by the owner on Jan 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
RouteStore.js
51 lines (44 loc) · 1.41 KB
/
RouteStore.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
/***
* Copyright (c) 2015, 2016 Alex Grant (@localnerve), LocalNerve LLC
* Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
*
* Extend the fluxible route store so routes can have action functions.
* Just de/rehydate the functions.
*/
'use strict';
var FluxibleRouteStore = require('fluxible-router').RouteStore;
var inherits = require('inherits');
var transformer = require('../utils').createFluxibleRouteTransformer({
actions: require('../actions/interface')
});
/**
* Creates a RouteStore.
*
* @class
*/
function RouteStore () {
FluxibleRouteStore.apply(this, arguments);
}
inherits(RouteStore, FluxibleRouteStore);
RouteStore.storeName = FluxibleRouteStore.storeName;
RouteStore.handlers = FluxibleRouteStore.handlers;
/**
* Dehydrates this object to state.
* Transforms routes to json.
*
* @returns {Object} The RouteStore represented as state.
*/
RouteStore.prototype.dehydrate = function dehydrate () {
var state = FluxibleRouteStore.prototype.dehydrate.apply(this, arguments);
state.routes = transformer.fluxibleToJson(state.routes);
return state;
};
/**
* Rehydrates this object from state.
* Creates routes from json using transformer.
*/
RouteStore.prototype.rehydrate = function rehydrate (state) {
state.routes = transformer.jsonToFluxible(state.routes);
return FluxibleRouteStore.prototype.rehydrate.apply(this, arguments);
};
module.exports = RouteStore;