Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Created March 27, 2018 08:58
Show Gist options
  • Save phpsmarter/7041165f8e34cc33e69c1edc625d5b5b to your computer and use it in GitHub Desktop.
Save phpsmarter/7041165f8e34cc33e69c1edc625d5b5b to your computer and use it in GitHub Desktop.
import * as R from 'ramda'
const initialState = {
user: {
name: 'jack',
token: 111111
},
goods: {
slug: 1,
wish: 2
}
}
const getPartialState = propName => (state = initialState) => R.prop(propName, state)
const getUser = getPartialState('user')
const getGoods = getPartialState('goods')
const getUserToken = prop => R.prop('token', prop)
const isAnonymous = R.cond([
[R.equals(null), R.always('isAnonymousUser')],
[R.T, state => 'welcome ' + getUser().name + '!']
])
const isAuthenticated = R.compose(isAnonymous, getUserToken, getUser)
console.log(isAuthenticated())
/*----------------------------------------------------------------------------- */
console.log(getUser())
console.log(getGoods())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment