Skip to content

Commit a4f8253

Browse files
committed
new: support flummox rc1
1 parent 8e73536 commit a4f8253

File tree

11 files changed

+97
-112
lines changed

11 files changed

+97
-112
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "server.js",
66
"dependencies": {
77
"async": "^0.9.2",
8-
"async-decorators": "^0.1.2",
8+
"async-decorators": "^0.1.3",
99
"autoprefixer-loader": "^1.2.0",
1010
"babel": "^5.5.5",
1111
"babel-core": "^5.5.5",
@@ -24,7 +24,7 @@
2424
"extract-text-webpack-plugin": "^0.3.5",
2525
"faker": "^2.1.4",
2626
"file-loader": "^0.8.4",
27-
"flummox": "^4.0.0-alpha2",
27+
"flummox": "^4.0.0-rc1",
2828
"fs-loader": "0.0.1",
2929
"google-map-react": "^0.3.0",
3030
"html-hint": "^0.0.2",

web/flux/actions/example_actions.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { Actions } from 'flummox';
2-
3-
export default class ExampleActions extends Actions {
4-
constructor() {
5-
super();
6-
}
7-
8-
initExampleInfo({title, info, source, next, prev}) {
9-
return {title, info, source, next, prev};
10-
}
1+
export default function createExampleActions() {
2+
return {
3+
initExampleInfo({title, info, source, next, prev}) {
4+
return {title, info, source, next, prev};
5+
}
6+
};
117
}

web/flux/actions/map_actions.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* emulate async server data query
33
*/
4-
import { Actions } from 'flummox';
54
import {memoize, serialize} from 'async-decorators';
65

76
import genMarkersData from 'components/examples/data/gen_markers_data.js';
@@ -12,35 +11,34 @@ const getDataAsync = (ms = 0, data = null) => new Promise(r => setTimeout(() =>
1211
const K_EMUL_ROUNDTRIP_TIME_MS = 100;
1312
const K_ROW_DEBOUNCE_INTERVAL = 16; // increase if you wanna show really big amount of markers
1413

15-
export default class MapActions extends Actions {
16-
constructor() {
17-
super();
18-
}
19-
20-
@serialize({raiseSkipError: false}) // possible memory leak, check
21-
@memoize({expireMs: 1000 * 60 * 15})
22-
async query(params) {
23-
return await getDataAsync(K_EMUL_ROUNDTRIP_TIME_MS, genMarkersData(params));
24-
}
25-
26-
changeBounds({center, zoom, bounds, marginBounds}) {
27-
return {center, zoom, bounds, marginBounds};
28-
}
29-
30-
tableHoveredRowIndexChange(index) {
31-
return index;
32-
}
33-
34-
markerHoverIndexChange(index) {
35-
return index;
36-
}
37-
38-
showBallon(index) {
39-
return index;
40-
}
41-
42-
@serialize({raiseSkipError: false}) // skips all but first and last
43-
async tableVisibleRowsChange({visibleRowFirst, visibleRowLast, maxVisibleRows}) {
44-
return await getDataAsync(K_ROW_DEBOUNCE_INTERVAL, {visibleRowFirst, visibleRowLast, maxVisibleRows});
45-
}
14+
15+
export default function createMapActions() {
16+
return {
17+
@serialize({raiseSkipError: false}) // possible memory leak, check
18+
@memoize({expireMs: 1000 * 60 * 15})
19+
async query(params) {
20+
return await getDataAsync(K_EMUL_ROUNDTRIP_TIME_MS, genMarkersData(params));
21+
},
22+
23+
changeBounds({center, zoom, bounds, marginBounds}) {
24+
return {center, zoom, bounds, marginBounds};
25+
},
26+
27+
tableHoveredRowIndexChange(index) {
28+
return index;
29+
},
30+
31+
markerHoverIndexChange(index) {
32+
return index;
33+
},
34+
35+
showBallon(index) {
36+
return index;
37+
},
38+
39+
@serialize({raiseSkipError: false}) // skips all but first and last
40+
async tableVisibleRowsChange({visibleRowFirst, visibleRowLast, maxVisibleRows}) {
41+
return await getDataAsync(K_ROW_DEBOUNCE_INTERVAL, {visibleRowFirst, visibleRowLast, maxVisibleRows});
42+
}
43+
};
4644
}

web/flux/actions/remote_actions.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import { Actions } from 'flummox';
21
import resource from 'utils/resource.js';
32

43
import {memoize, serialize /*, isSkipError */} from 'async-decorators';
54

6-
export default class RemoteActions extends Actions {
7-
constructor(url) {
8-
super();
9-
this.resource = resource(url);
10-
}
5+
export default function createRemoteActions(url) {
6+
const resource_ = resource(url);
117

12-
@serialize({raiseSkipError: false}) // possible memory leak, check
13-
@memoize({expireMs: 1000 * 60 * 15})
14-
async query(params) {
15-
return await this.resource
16-
.get(params);
17-
}
8+
return {
9+
@serialize({raiseSkipError: false}) // possible memory leak, check
10+
@memoize({expireMs: 1000 * 60 * 15})
11+
async query(params) {
12+
return await resource_
13+
.get(params);
14+
},
1815

19-
@serialize({raiseSkipError: false})
20-
async save(params, obj) {
21-
return await this.resource
22-
.save(params, obj);
23-
}
16+
@serialize({raiseSkipError: false})
17+
async save(params, obj) {
18+
return await resource_
19+
.save(params, obj);
20+
}
21+
};
2422
}

web/flux/actions/route_actions.js

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
import { Actions } from 'flummox';
2-
31
import routeTemplate from 'utils/route_template.js';
42
import utilsText from 'utils/text.js';
53

6-
export default class RouteActions extends Actions {
7-
8-
constructor(page) {
9-
super();
10-
this.page = page;
11-
}
12-
13-
routeTemplatesCache_ = {};
14-
15-
defaultRoute({routeName, routePath, routeContext, routeParams}) {
16-
return {routeName, routePath, routeContext, routeParams};
17-
}
18-
19-
gotoLink(link) {
20-
this.page(link);
21-
}
22-
23-
gotoLinkWParams(link, params, routeContextParams, defaultParams) {
24-
// const routeContextParams = routes_store.get_route_context_params ();
25-
26-
if (routeContextParams && link !== undefined && typeof link === 'string') {
27-
if (!(link in this.routeTemplatesCache_)) {
28-
this.routeTemplatesCache_[link] = routeTemplate(link);
29-
}
30-
const linkTemplate = this.routeTemplatesCache_[link];
31-
const evaluatedLink = linkTemplate(
32-
utilsText.encode_link_object_properties(
33-
Object.assign(
34-
{},
35-
defaultParams || {},
36-
routeContextParams.toJS(),
37-
params || {}
4+
export default function createRouteActions(page) {
5+
const routeTemplatesCache_ = {};
6+
7+
return {
8+
defaultRoute({routeName, routePath, routeContext, routeParams}) {
9+
return {routeName, routePath, routeContext, routeParams};
10+
},
11+
12+
gotoLink(link) {
13+
page(link);
14+
},
15+
16+
gotoLinkWParams(link, params, routeContextParams, defaultParams) {
17+
// const routeContextParams = routes_store.get_route_context_params ();
18+
19+
if (routeContextParams && link !== undefined && typeof link === 'string') {
20+
if (!(link in routeTemplatesCache_)) {
21+
routeTemplatesCache_[link] = routeTemplate(link);
22+
}
23+
const linkTemplate = routeTemplatesCache_[link];
24+
const evaluatedLink = linkTemplate(
25+
utilsText.encode_link_object_properties(
26+
Object.assign(
27+
{},
28+
defaultParams || {},
29+
routeContextParams.toJS(),
30+
params || {}
31+
)
3832
)
39-
)
40-
);
33+
);
4134

42-
this.page(evaluatedLink);
43-
} else {
44-
throw new Error('unrecognized link');
35+
page(evaluatedLink);
36+
} else {
37+
throw new Error('unrecognized link');
38+
}
4539
}
46-
}
40+
};
4741
}

web/flux/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react/addons';
22

33
import AppFlux from 'utils/appflux.js';
4-
import FluxComponent from 'flummox/component';
4+
import {FluxComponent} from 'flummox/addons/react';
55

66
import Main from 'components/main.jsx';
77

web/flux/components/decorators/flux_component_decorator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TODO replace fluxComponentDecorator with import {connect} from 'flummox/connect'
22
import React, { Component } from 'react';
3-
import FluxComponent from 'flummox/component';
3+
import {FluxComponent} from 'flummox/addons/react';
44
import shouldPureComponentUpdate from 'react-pure-render/function';
55

66
export default function fluxComponentDecorator(fluxComponentProps) {

web/flux/components/examples/x_main/main_map_page.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {PropTypes, Component} from 'react/addons';
22
import shouldPureComponentUpdate from 'react-pure-render/function';
33

4-
import FluxComponent from 'flummox/component';
4+
import {FluxComponent} from 'flummox/addons/react';
55

66
import MainMapLayout from './main_map_layout.jsx';
77
import IceTable from 'components/controls/fixed_table_examples/ice_table.jsx';

web/flux/components/main.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import shouldPureComponentUpdate from 'react-pure-render/function';
33
import {routeNames} from 'create_routes.js';
44
import {examples} from 'consts/example_defs.js';
55

6-
import FluxComponent from 'flummox/component';
6+
import {FluxComponent} from 'flummox/addons/react';
77

88
import MainMapPage from './examples/x_main/main_map_page.jsx';
99
import SimpleMapPage from './examples/x_simple/simple_map_page.jsx';

web/flux/initflux.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// import RemoteActions from 'actions/remote_actions.js';
2-
import MapActions from 'actions/map_actions.js';
3-
import ExampleActions from 'actions/example_actions.js';
1+
import createMapActions from 'actions/map_actions.js';
2+
import createExampleActions from 'actions/example_actions.js';
43

54
import MapStore from 'stores/map_store.js';
65
import ExampleStore from 'stores/example_store.js';
76

87
export default function initFlux(flux) {
9-
const mapActions = flux.createActions('map', MapActions);
8+
const mapActions = flux.createActions('map', createMapActions());
109
flux.createStore('map', MapStore, { mapActions });
1110

12-
const exampleActions = flux.createActions('example', ExampleActions);
11+
const exampleActions = flux.createActions('example', createExampleActions());
1312
flux.createStore('example', ExampleStore, { exampleActions });
1413
// you nedd to return actions to pass them into create_routes
1514
return {mapActions, exampleActions};

web/flux/utils/appflux.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Flummox } from 'flummox';
2-
import RouteActions from 'actions/route_actions.js';
2+
import createRouteActions from 'actions/route_actions.js';
33
import RouteStore from 'stores/route_store.js';
44

55
import initFlux from 'initflux.js';
@@ -14,8 +14,8 @@ export default class AppFlux extends Flummox {
1414
super();
1515

1616
const pageRouter = createPage(); // pagejs роутер
17+
const routeActions = this.createActions('route', createRouteActions(pageRouter));
1718

18-
const routeActions = this.createActions('route', RouteActions, pageRouter);
1919
this.createStore('route', RouteStore, { routeActions });
2020

2121
const actions = initFlux(this);

0 commit comments

Comments
 (0)