Created
March 27, 2018 08:58
-
-
Save phpsmarter/7041165f8e34cc33e69c1edc625d5b5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 * 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