-
-
Save meshenka/30891a062a21e96dfa53 to your computer and use it in GitHub Desktop.
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
import { action } from 'common/utils/redux/redux'; | |
@action | |
export class Actions { | |
static types = { | |
set3d: Symbol('set3d') | |
}; | |
static set3d(val) { | |
return { | |
type: Actions.types.set3d, | |
val | |
}; | |
} | |
} |
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
import React, { Component } from 'react'; | |
import { Provider } from 'react-redux'; | |
import { configureStore } from 'common/utils/redux/redux'; | |
import { Viz } from './Viz'; | |
import { Reducer } from './Reducer'; | |
const store = configureStore(Reducer, { | |
options: { | |
layout: { | |
type: 'radialTree', | |
is3d: false | |
} | |
}, | |
model: {} | |
}); | |
export class Container extends Component { | |
render() { | |
return ( | |
<Provider store={store}> | |
<Viz /> | |
</Provider> | |
) | |
} | |
} |
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
// THIS ISNT REALLY RELEVANT BUT WANTED TO DISCLOSE ANYWAY | |
// http://raganwald.com/2015/06/26/decorators-in-es7.html | |
export function mixin (behaviour) { | |
const staticKeys = Reflect.ownKeys(behaviour.prototype ? behaviour : {}); | |
const instanceKeys = Reflect.ownKeys(behaviour.prototype || behaviour); | |
const typeTag = Symbol('isa'); | |
function _mixin (clazz) { | |
for (let property of staticKeys) { | |
Object.defineProperty(clazz, property, { | |
value: behaviour[property], | |
writable: true, | |
static: true | |
}); | |
} | |
for (let property of instanceKeys) { | |
Object.defineProperty(clazz.prototype, property, { | |
value: behaviour[property], | |
writable: true | |
}); | |
} | |
Object.defineProperty(clazz.prototype, typeTag, { value: true }); | |
return clazz; | |
} | |
Object.defineProperty(_mixin, Symbol.hasInstance, { | |
value: (i) => !!i[typeTag] | |
}); | |
return _mixin; | |
} |
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
import { Actions } from './Actions'; | |
import { reduce } from 'common/utils/redux/redux'; | |
@reduce | |
export class Reducer { | |
static [Actions.types.set3d](state, { val }) { | |
state.options.layout.is3d = val; | |
return state; | |
} | |
} |
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
import { bindActionCreators as reduxBinder, applyMiddleware, createStore } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import { mixin } from '../decorators/mixin'; | |
export const action = mixin(class { | |
static actors (clazz) { | |
return Object.keys(clazz.types).reduce((newObj, k) => { | |
newObj[k] = clazz[k]; | |
return newObj; | |
}, {}); | |
} | |
}); | |
export function bindActionCreators(act, dispatch) { | |
return reduxBinder(act.actors(act), dispatch); | |
}; | |
export function configureStore(reducers, initialState = {}) { | |
return createStore( | |
reducers.invoke(), | |
initialState, | |
applyMiddleware(thunk) | |
); | |
} | |
export const reduce = mixin(class { | |
static invoke (initalState = {}) { | |
return (state = initalState, action) => { | |
const handler = this[action.type]; | |
return handler ? | |
handler(state, action) : | |
state; | |
}; | |
} | |
}); |
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
import React, { Component, PropTypes } from 'react'; | |
import { connect } from 'react-redux'; | |
import { bindActionCreators } from 'common/utils/redux/redux'; | |
import { Actions } from './Actions'; | |
import { VizMenu } from './vizMenu/VizMenu'; | |
@connect(state => state) | |
export class Viz extends Component { | |
static propTypes = { | |
model: PropTypes.object, | |
options: PropTypes.object | |
}; | |
// componentWillMount() { | |
// this.unsubscribe = store.subscribe(() => { | |
// return this.updateState(); | |
// }); | |
// } | |
// componentWillUnmount() { | |
// this.unsubscribe(); | |
// } | |
// updateState() { | |
// this.setState(store.getState()); | |
// } | |
render() { | |
const { dispatch, options, model } = this.props; | |
const actions = bindActionCreators(Actions, dispatch); | |
return ( | |
<div> | |
<VizMenu | |
options={options} | |
{...actions} | |
/> | |
<Graph | |
options={options} | |
model={model} | |
/> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment