Last active
September 23, 2019 05:14
-
-
Save protoEvangelion/3f20e9c78c4dc9bfbbe6c7d6bf04a2e9 to your computer and use it in GitHub Desktop.
I wanted to do a side by side of Immer vs Immutable JS
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
// Immutable | |
import { fromJS } from 'immutable' | |
const args = fromJS(nopt(Command.DETAILS.options, Command.DETAILS.shorthands, process.argv, 2)) | |
const secondArg = args.getIn(['argv', 'remain']).get(1) | |
const remote = args.get('remote') || config.default_remote | |
const remoteUrl = git.getRemoteUrl(remote) | |
const options = args.merge({ | |
remote, | |
number: args.get('number') || secondArg, | |
loggedUser: getUser(), | |
remoteUser: git.getUserFromRemoteUrl(remoteUrl), | |
repo: args.get('repo') || git.getRepoFromRemoteURL(remoteUrl), | |
currentBranch: testing ? 'master' : git.getCurrentBranch(), | |
github_host: config.github_host, | |
github_gist_host: config.github_gist_host, | |
}) | |
let user = args.get('user') | |
if (!user) { | |
user = | |
options.get('repo') || options.get('all') | |
? options.get('loggedUser') | |
: process.env.GH_USER || options.get('remoteUser') || options.get('loggedUser') | |
} | |
function onlyReplaceIfTruthy(oldVal, newVal) { | |
return Boolean(newVal) ? newVal : oldVal | |
} | |
let expandedAliases = {} | |
if (config.alias) { | |
expandedAliases = { | |
fwd: config.alias[options.get('fwd')], | |
submit: config.alias[options.get('submit')], | |
user: config.alias[user] || user, | |
} | |
} | |
const finalOptions = options.mergeWith(onlyReplaceIfTruthy, { user, ...expandedAliases }) | |
// Immer | |
import { produce } from 'immer' | |
const args = nopt(Command.DETAILS.options, Command.DETAILS.shorthands, process.argv, 2) | |
const options = produce(args, draft => { | |
const secondArg = draft.argv.remain[1] | |
const remote = draft.remote || config.default_remote | |
const remoteUrl = git.getRemoteUrl(remote) | |
draft.remote = remote | |
draft.number = draft.number || secondArg | |
draft.loggedUser = getUser() | |
draft.remoteUser = git.getUserFromRemoteUrl(remoteUrl) | |
draft.repo = draft.repo || git.getRepoFromRemoteURL(remoteUrl) | |
draft.currentBranch = git.getCurrentBranch() | |
draft.github_host = config.github_host | |
draft.github_gist_host = config.github_gist_host | |
if (!draft.user) { | |
if (draft.repo || draft.all) { | |
draft.user = draft.loggedUser | |
} else { | |
draft.user = process.env.GH_USER || draft.remoteUser || draft.loggedUser | |
} | |
} | |
if (config.alias) { | |
draft.fwd = config.alias[draft.fwd] || draft.fwd | |
draft.submit = config.alias[draft.submit] || draft.submit | |
draft.user = config.alias[draft.user] || draft.user | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment