Skip to content

Instantly share code, notes, and snippets.

@SPY
Last active November 18, 2015 10:56
Show Gist options
  • Save SPY/629d2e7c6bfc696ce28d to your computer and use it in GitHub Desktop.
Save SPY/629d2e7c6bfc696ce28d to your computer and use it in GitHub Desktop.
import {actionCreators, Action} from '../actions/Action'
export class App extends React.Component<AppProps, {}> {
public static childContextTypes: any = {}
private getChildContext() {
const context: any = {}
const props = this.props as any
Object.keys(this.props).forEach(prop => {
if (typeof props[prop] == 'function' && prop in actionCreators) {
context[prop] = props[prop]
}
})
return context
}
render() {
return (
<div className="app">
{screenRender()}
</div>
)
}
}
Object.keys(actionCreators).forEach(actionCreator => {
App.childContextTypes[actionCreator] = React.PropTypes.func
})
function mapDispatchToProps(dispatch: Dispatch<Action>) {
return bindActionCreators(actionCreators, dispatch);
}
export const Root = connect(mapStateToProps, mapDispatchToProps)(App);
import {PropTypes} from 'react'
import {Screen} from '../store/State'
export function connectActions(...actions: string[]) {
return (ctor: any) => {
ctor.contextTypes = {}
actions.forEach(action => {
ctor.contextTypes[action] = PropTypes.func
})
}
}
export interface LogoutMethod {
logout(): void;
}
export interface LoginMethod {
login(email: string, password: string): void;
}
export interface ChangeScreenMethod {
changeScreen(screen: Screen): void;
}
import * as React from 'react'
import {Screen} from '../../store/State'
import {BottomNav, BottomNavItem} from './BottomNav'
import {block, $} from '../../utils/Bem'
import {autobind} from '../../utils/Autobind'
import {connectActions, LogoutMethod, ChangeScreenMethod} from '../../actions/ConnectActions'
import './InnerScreen.less'
export interface InnerScreenProps extends React.Props<InnerScreen> {
screen: Screen;
headerButtons?: React.ReactElement<any>;
}
@connectActions('logout', 'changeScreen')
export class InnerScreen extends React.Component<InnerScreenProps, InnerScreenState> {
context: LogoutMethod & ChangeScreenMethod
render() {
const {elem} = block('inner-screen')
const menu: MenuItems = {
['logout']: (<span onClick={this.context.logout}>Logout</span>)
}
return (
<div className="inner-screen">
<BottomNav className={elem("bottom-nav")} changeScreen={this.context.changeScreen}>
<BottomNavItem
screen={Screen.Symbols}
title="Symbols"
active={this.props.screen == Screen.Symbols}
icon={require('images/icons/symbols.png')}
/>
</BottomNav>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment