85 lines
1.8 KiB
Plaintext
85 lines
1.8 KiB
Plaintext
snippet reactConnectedRoute "React template" b
|
|
import React from 'react'
|
|
import { connect } from 'react-redux'
|
|
import { isLogin } from 'utils/self'
|
|
import { Redirect, Route } from 'react-router-dom'
|
|
|
|
export default connect((state, ownProps) => {
|
|
const { self } = state
|
|
return { self }
|
|
})(({ component: Component, ...rest }) => {
|
|
const { self } = rest
|
|
return <Route
|
|
{...rest}
|
|
render={props => isLogin(self) ? <Component {...props} /> : <Redirect
|
|
to={{
|
|
pathname: '/login',
|
|
state: { from: props.location }
|
|
}} />
|
|
}
|
|
/>
|
|
})
|
|
endsnippet
|
|
|
|
snippet reactComponent "React template" b
|
|
import React, { Component } from 'react'
|
|
|
|
export default class extends Component {
|
|
render () {
|
|
}
|
|
}
|
|
endsnippet
|
|
|
|
snippet reactConnect "React template" b
|
|
import component from './component'
|
|
import { connect } from 'react-redux'
|
|
|
|
export default connect((state, ownProps) => ({
|
|
}), {
|
|
})(component)
|
|
endsnippet
|
|
|
|
snippet TODO "Javascript Todo" b
|
|
// TODO: ${1:desc} `echo $USER` `!v strftime("%c")` ${2}
|
|
endsnippet
|
|
|
|
snippet connect "react redux connect" b
|
|
export default connect((state, ownProps) => {
|
|
return {
|
|
}
|
|
})($1)
|
|
endsnippet
|
|
|
|
snippet Card "Default Expandable Card" b
|
|
<Card initiallyExpanded={false} className="MT-5">
|
|
<CardTitle showExpandableButton title="$1" />
|
|
<CardText expandable>
|
|
</CardText>
|
|
<CardActions expandable>
|
|
<RaisedButton primary label="保存" onTouchTap={$2} />
|
|
</CardActions>
|
|
</Card>
|
|
endsnippet
|
|
|
|
snippet redux "redux" b
|
|
export const SET_${1/\w/\u$0/g} = 'SET_${1/\w/\u$0/g}'
|
|
import {store} from 'redux/store'
|
|
import {Map} from 'immutable'
|
|
export default function (${1} = Map({}), action) {
|
|
// let {$1Id} = action
|
|
switch (action.type) {
|
|
case SET_${1/\w/\u$0/g}:
|
|
return action.$1
|
|
default:
|
|
return $1
|
|
}
|
|
}
|
|
|
|
export function set${1/\w+\s*/\u$0/} ($1) {
|
|
store.dispatch({
|
|
type: SET_${1/\w/\u$0/g},
|
|
$1
|
|
})
|
|
}
|
|
endsnippet
|