Skip to content

Commit

Permalink
fix: replace object.mixin with Object.assign (#6138)
Browse files Browse the repository at this point in the history
* fix: replace `object.mixin` with `Object.assign`

* fix: deprecate `object.mixin`
  • Loading branch information
derwehr committed May 4, 2022
1 parent 71e8356 commit df41c23
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
5 changes: 2 additions & 3 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const constants = goog.require('Blockly.constants');
const eventUtils = goog.require('Blockly.Events.utils');
const fieldRegistry = goog.require('Blockly.fieldRegistry');
const idGenerator = goog.require('Blockly.utils.idGenerator');
const object = goog.require('Blockly.utils.object');
const parsing = goog.require('Blockly.utils.parsing');
/* eslint-disable-next-line no-unused-vars */
const {Abstract} = goog.requireType('Blockly.Events.Abstract');
Expand Down Expand Up @@ -342,7 +341,7 @@ class Block {
if (!prototype || typeof prototype !== 'object') {
throw TypeError('Invalid block definition for type: ' + prototypeName);
}
object.mixin(this, prototype);
Object.assign(this, prototype);
}

workspace.addTopBlock(this);
Expand Down Expand Up @@ -1705,7 +1704,7 @@ class Block {
JSON.stringify(overwrites));
}
}
object.mixin(this, mixinObj);
Object.assign(this, mixinObj);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions core/renderers/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ goog.module('Blockly.blockRendering.ConstantProvider');

const colour = goog.require('Blockly.utils.colour');
const dom = goog.require('Blockly.utils.dom');
const object = goog.require('Blockly.utils.object');
const svgPaths = goog.require('Blockly.utils.svgPaths');
const userAgent = goog.require('Blockly.utils.userAgent');
const parsing = goog.require('Blockly.utils.parsing');
Expand Down Expand Up @@ -823,7 +822,7 @@ class ConstantProvider {
// Make a new object with all of the same properties.
const valid = /** @type {!Theme.BlockStyle} */ ({});
if (blockStyle) {
object.mixin(valid, blockStyle);
Object.assign(valid, blockStyle);
}
// Validate required properties.
const parsedColour =
Expand Down
5 changes: 2 additions & 3 deletions core/renderers/common/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
goog.module('Blockly.blockRendering.Renderer');

const debug = goog.require('Blockly.blockRendering.debug');
const object = goog.require('Blockly.utils.object');
/* eslint-disable-next-line no-unused-vars */
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -97,7 +96,7 @@ class Renderer {
this.constants_ = this.makeConstants_();
if (opt_rendererOverrides) {
this.overrides = opt_rendererOverrides;
object.mixin(this.constants_, opt_rendererOverrides);
Object.assign(this.constants_, opt_rendererOverrides);
}
this.constants_.setTheme(theme);
this.constants_.init();
Expand Down Expand Up @@ -126,7 +125,7 @@ class Renderer {
previousConstants.dispose();
this.constants_ = this.makeConstants_();
if (this.overrides) {
object.mixin(this.constants_, this.overrides);
Object.assign(this.constants_, this.overrides);
}
// Ensure the constant provider's random identifier does not change.
this.constants_.randomIdentifier = previousConstants.randomIdentifier;
Expand Down
3 changes: 1 addition & 2 deletions core/toolbox/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const Css = goog.require('Blockly.Css');
const aria = goog.require('Blockly.utils.aria');
const colourUtils = goog.require('Blockly.utils.colour');
const dom = goog.require('Blockly.utils.dom');
const object = goog.require('Blockly.utils.object');
const parsing = goog.require('Blockly.utils.parsing');
const registry = goog.require('Blockly.registry');
const toolbox = goog.require('Blockly.utils.toolbox');
Expand Down Expand Up @@ -198,7 +197,7 @@ class ToolboxCategory extends ToolboxItem {
parseCategoryDef_(categoryDef) {
this.name_ = parsing.replaceMessageReferences(categoryDef['name']);
this.colour_ = this.getColour_(categoryDef);
object.mixin(
Object.assign(
this.cssConfig_, categoryDef['cssconfig'] || categoryDef['cssConfig']);
}

Expand Down
3 changes: 1 addition & 2 deletions core/toolbox/separator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ goog.module('Blockly.ToolboxSeparator');

const Css = goog.require('Blockly.Css');
const dom = goog.require('Blockly.utils.dom');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/* eslint-disable-next-line no-unused-vars */
const toolbox = goog.requireType('Blockly.utils.toolbox');
Expand Down Expand Up @@ -54,7 +53,7 @@ class ToolboxSeparator extends ToolboxItem {
this.htmlDiv_ = null;

const cssConfig = separatorDef['cssconfig'] || separatorDef['cssConfig'];
object.mixin(this.cssConfig_, cssConfig);
Object.assign(this.cssConfig_, cssConfig);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions core/utils/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
goog.module('Blockly.utils.object');

const deprecation = goog.require('Blockly.utils.deprecation');

/**
* Inherit the prototype methods from one constructor into another.
Expand Down Expand Up @@ -43,11 +44,14 @@ exports.inherits = inherits;

/**
* Copies all the members of a source object to a target object.
* @deprecated Use Object.assign. (2022 May)
* @param {!Object} target Target.
* @param {!Object} source Source.
* @alias Blockly.utils.object.mixin
*/
const mixin = function(target, source) {
deprecation.warn(
'Blockly.utils.object.mixin', 'May 2022', 'May 2023', 'Object.assign');
for (const x in source) {
target[x] = source[x];
}
Expand Down
5 changes: 2 additions & 3 deletions core/variable_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const arrayUtils = goog.require('Blockly.utils.array');
const dialog = goog.require('Blockly.dialog');
const eventUtils = goog.require('Blockly.Events.utils');
const idGenerator = goog.require('Blockly.utils.idGenerator');
const object = goog.require('Blockly.utils.object');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
const {Msg} = goog.require('Blockly.Msg');
Expand Down Expand Up @@ -343,9 +342,9 @@ class VariableMap {
*/
getVariableTypes(ws) {
const variableMap = {};
object.mixin(variableMap, this.variableMap_);
Object.assign(variableMap, this.variableMap_);
if (ws && ws.getPotentialVariableMap()) {
object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_);
Object.assign(variableMap, ws.getPotentialVariableMap().variableMap_);
}
const types = Object.keys(variableMap);
let hasEmpty = false;
Expand Down

0 comments on commit df41c23

Please sign in to comment.