Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(theme/view): simplify assignIn #3987

Merged
merged 1 commit into from Dec 19, 2019
Merged

Conversation

@SukkaW
Copy link
Member

SukkaW commented Dec 18, 2019

What does it do?

The continuation of #3969 (#3753).

underscore.js has a createAssigner() which is a internal function for _.extend, _.defaults & _.assign:

_.extend = createAssigner(_.allKeys);
_.assign = createAssigner(_.keys);
_.defaults = createAssigner(_.allKeys, true);

When bring up #3969, I just simply merge and rewrite createAssigner(_.allKeys):

// Below is a part of _.allKeys which is unnecessary for assignIn itself
const keys = [];
for (const key in source) keys.push(key);

// Iterate Object from keys
const l = keys.length;	
for (let i = 0; i < l; i++) {
  const key = keys[i];
  obj[key] = source[key];
}

This PR simplify the assignIn() by directly iterating Object.

How to test

git clone -b simplify-assignIn https://github.com/sukkaw/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.
@SukkaW SukkaW requested review from curbengh and hexojs/core Dec 18, 2019
@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 18, 2019

Coverage Status

Coverage decreased (-0.004%) to 97.114% when pulling 809cb78 on SukkaW:simplify-assignIn into fa59eb2 on hexojs:master.

@SukkaW SukkaW merged commit 1ccc292 into hexojs:master Dec 19, 2019
3 of 4 checks passed
3 of 4 checks passed
coverage/coveralls Coverage decreased (-0.004%) to 97.114%
Details
Travis CI - Pull Request Build Passed
Details
codeclimate 1 fixed issue
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@SukkaW SukkaW mentioned this pull request Dec 21, 2019
1 of 1 task complete
oncletom added a commit to oncletom/hexo that referenced this pull request Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.