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

chore(core): use object.assign to test the trade-off between size and perf #4365

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions compat/src/util.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
* @param {O} obj The object to copy properties to
* @param {P} props The object to copy properties from
* @returns {O & P}
*/
export function assign(obj, props) {
for (let i in props) obj[i] = props[i];
return /** @type {O & P} */ (obj);
}
export const assign = Object.assign;

/**
* Check if two objects have a different shape
Expand Down
12 changes: 1 addition & 11 deletions debug/src/util.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
* @param {O} obj The object to copy properties to
* @param {P} props The object to copy properties from
* @returns {O & P}
*/
export function assign(obj, props) {
for (let i in props) obj[i] = props[i];
return /** @type {O & P} */ (obj);
}
export const assign = Object.assign;

export function isNaN(value) {
return value !== value;
Expand Down
17 changes: 2 additions & 15 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import { EMPTY_ARR } from './constants';

export const isArray = Array.isArray;

/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
* @param {O} obj The object to copy properties to
* @param {P} props The object to copy properties from
* @returns {O & P}
*/
export function assign(obj, props) {
// @ts-expect-error We change the type of `obj` to be `O & P`
for (let i in props) obj[i] = props[i];
return /** @type {O & P} */ (obj);
}
export const assign = Object.assign;
export const slice = EMPTY_ARR.slice;

/**
* Remove a child node from its parent if attached. This is a workaround for
Expand All @@ -25,5 +14,3 @@ export function removeNode(node) {
let parentNode = node.parentNode;
if (parentNode) parentNode.removeChild(node);
}

export const slice = EMPTY_ARR.slice;
12 changes: 1 addition & 11 deletions test/_util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ import { teardown as testUtilTeardown } from 'preact/test-utils';

/** @jsx createElement */

/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
* @param {O} obj The object to copy properties to
* @param {P} props The object to copy properties from
* @returns {O & P}
*/
function assign(obj, props) {
for (let i in props) obj[i] = props[i];
return /** @type {O & P} */ (obj);
}
export const assign = Object.assign;

export function supportsPassiveEvents() {
let supported = false;
Expand Down
Loading