Skip to content

refactor(theme/view): simplify assignIn#3987

Merged
SukkaW merged 1 commit into
hexojs:masterfrom
SukkaW:simplify-assignIn
Dec 19, 2019
Merged

refactor(theme/view): simplify assignIn#3987
SukkaW merged 1 commit into
hexojs:masterfrom
SukkaW:simplify-assignIn

Conversation

@SukkaW

@SukkaW SukkaW commented Dec 18, 2019

Copy link
Copy Markdown
Member

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 a team and curbengh December 18, 2019 15:45
@coveralls

Copy link
Copy Markdown

Coverage Status

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants