mirror of
https://github.com/videojs/video.js.git
synced 2024-12-23 02:04:34 +02:00
remove merge-options in favor of obj.merge
This commit is contained in:
parent
a5fd093a42
commit
f641c0f6d3
@ -10,7 +10,7 @@ import * as Dom from './utils/dom.js';
|
|||||||
import * as Fn from './utils/fn.js';
|
import * as Fn from './utils/fn.js';
|
||||||
import * as Guid from './utils/guid.js';
|
import * as Guid from './utils/guid.js';
|
||||||
import {toTitleCase, toLowerCase} from './utils/str.js';
|
import {toTitleCase, toLowerCase} from './utils/str.js';
|
||||||
import mergeOptions from './utils/merge-options.js';
|
import {merge} from './utils/obj.js';
|
||||||
import computedStyle from './utils/computed-style';
|
import computedStyle from './utils/computed-style';
|
||||||
import Map from './utils/map.js';
|
import Map from './utils/map.js';
|
||||||
import Set from './utils/set.js';
|
import Set from './utils/set.js';
|
||||||
@ -69,10 +69,10 @@ class Component {
|
|||||||
this.parentComponent_ = null;
|
this.parentComponent_ = null;
|
||||||
|
|
||||||
// Make a copy of prototype.options_ to protect against overriding defaults
|
// Make a copy of prototype.options_ to protect against overriding defaults
|
||||||
this.options_ = mergeOptions({}, this.options_);
|
this.options_ = merge({}, this.options_);
|
||||||
|
|
||||||
// Updated options with supplied options
|
// Updated options with supplied options
|
||||||
options = this.options_ = mergeOptions(this.options_, options);
|
options = this.options_ = merge(this.options_, options);
|
||||||
|
|
||||||
// Get ID from options or options element if one is supplied
|
// Get ID from options or options element if one is supplied
|
||||||
this.id_ = options.id || (options.el && options.el.id);
|
this.id_ = options.id || (options.el && options.el.id);
|
||||||
@ -215,7 +215,7 @@ class Component {
|
|||||||
/**
|
/**
|
||||||
* Deep merge of options objects with new options.
|
* Deep merge of options objects with new options.
|
||||||
* > Note: When both `obj` and `options` contain properties whose values are objects.
|
* > Note: When both `obj` and `options` contain properties whose values are objects.
|
||||||
* The two properties get merged using {@link module:mergeOptions}
|
* The two properties get merged using {@link module:obj.merge}
|
||||||
*
|
*
|
||||||
* @param {Object} obj
|
* @param {Object} obj
|
||||||
* The object that contains new options.
|
* The object that contains new options.
|
||||||
@ -228,7 +228,7 @@ class Component {
|
|||||||
return this.options_;
|
return this.options_;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options_ = mergeOptions(this.options_, obj);
|
this.options_ = merge(this.options_, obj);
|
||||||
return this.options_;
|
return this.options_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Component from './component.js';
|
import Component from './component.js';
|
||||||
import mergeOptions from './utils/merge-options.js';
|
import {merge} from './utils/obj.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
import * as browser from './utils/browser.js';
|
import * as browser from './utils/browser.js';
|
||||||
import window from 'global/window';
|
import window from 'global/window';
|
||||||
@ -40,7 +40,7 @@ class LiveTracker extends Component {
|
|||||||
*/
|
*/
|
||||||
constructor(player, options) {
|
constructor(player, options) {
|
||||||
// LiveTracker does not need an element
|
// LiveTracker does not need an element
|
||||||
const options_ = mergeOptions(defaults, options, {createEl: false});
|
const options_ = merge(defaults, options, {createEl: false});
|
||||||
|
|
||||||
super(player, options_);
|
super(player, options_);
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import * as stylesheet from './utils/stylesheet.js';
|
|||||||
import FullscreenApi from './fullscreen-api.js';
|
import FullscreenApi from './fullscreen-api.js';
|
||||||
import MediaError from './media-error.js';
|
import MediaError from './media-error.js';
|
||||||
import safeParseTuple from 'safe-json-parse/tuple';
|
import safeParseTuple from 'safe-json-parse/tuple';
|
||||||
import {assign} from './utils/obj';
|
|
||||||
import mergeOptions from './utils/merge-options.js';
|
|
||||||
import {silencePromise, isPromise} from './utils/promise';
|
import {silencePromise, isPromise} from './utils/promise';
|
||||||
import textTrackConverter from './tracks/text-track-list-converter.js';
|
import textTrackConverter from './tracks/text-track-list-converter.js';
|
||||||
import ModalDialog from './modal-dialog';
|
import ModalDialog from './modal-dialog';
|
||||||
@ -34,7 +32,7 @@ import {ALL as TRACK_TYPES} from './tracks/track-types';
|
|||||||
import filterSource from './utils/filter-source';
|
import filterSource from './utils/filter-source';
|
||||||
import {getMimetype, findMimetype} from './utils/mimetypes';
|
import {getMimetype, findMimetype} from './utils/mimetypes';
|
||||||
import {hooks} from './utils/hooks';
|
import {hooks} from './utils/hooks';
|
||||||
import {isObject} from './utils/obj';
|
import {assign, merge, isObject} from './utils/obj';
|
||||||
import keycode from 'keycode';
|
import keycode from 'keycode';
|
||||||
|
|
||||||
// The following imports are used only to ensure that the corresponding modules
|
// The following imports are used only to ensure that the corresponding modules
|
||||||
@ -504,7 +502,7 @@ class Player extends Component {
|
|||||||
// as well so they don't need to reach back into the player for options later.
|
// as well so they don't need to reach back into the player for options later.
|
||||||
// We also need to do another copy of this.options_ so we don't end up with
|
// We also need to do another copy of this.options_ so we don't end up with
|
||||||
// an infinite loop.
|
// an infinite loop.
|
||||||
const playerOptionsCopy = mergeOptions(this.options_);
|
const playerOptionsCopy = merge(this.options_);
|
||||||
|
|
||||||
// Load plugins
|
// Load plugins
|
||||||
if (options.plugins) {
|
if (options.plugins) {
|
||||||
@ -1535,7 +1533,7 @@ class Player extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update `currentSource` cache always
|
// update `currentSource` cache always
|
||||||
this.cache_.source = mergeOptions({}, srcObj, {src, type});
|
this.cache_.source = merge({}, srcObj, {src, type});
|
||||||
|
|
||||||
const matchingSources = this.cache_.sources.filter((s) => s.src && s.src === src);
|
const matchingSources = this.cache_.sources.filter((s) => s.src && s.src === src);
|
||||||
const sourceElSources = [];
|
const sourceElSources = [];
|
||||||
@ -4648,7 +4646,7 @@ class Player extends Component {
|
|||||||
* An array of of supported languages
|
* An array of of supported languages
|
||||||
*/
|
*/
|
||||||
languages() {
|
languages() {
|
||||||
return mergeOptions(Player.prototype.options_.languages, this.languages_);
|
return merge(Player.prototype.options_.languages, this.languages_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4659,7 +4657,7 @@ class Player extends Component {
|
|||||||
* Object representing the current of track info
|
* Object representing the current of track info
|
||||||
*/
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
const options = mergeOptions(this.options_);
|
const options = merge(this.options_);
|
||||||
const tracks = options.tracks;
|
const tracks = options.tracks;
|
||||||
|
|
||||||
options.tracks = [];
|
options.tracks = [];
|
||||||
@ -4668,7 +4666,7 @@ class Player extends Component {
|
|||||||
let track = tracks[i];
|
let track = tracks[i];
|
||||||
|
|
||||||
// deep merge tracks and null out player so no circular references
|
// deep merge tracks and null out player so no circular references
|
||||||
track = mergeOptions(track);
|
track = merge(track);
|
||||||
track.player = undefined;
|
track.player = undefined;
|
||||||
options.tracks[i] = track;
|
options.tracks[i] = track;
|
||||||
}
|
}
|
||||||
@ -4942,7 +4940,7 @@ class Player extends Component {
|
|||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
// Clone the media object so it cannot be mutated from outside.
|
// Clone the media object so it cannot be mutated from outside.
|
||||||
this.cache_.media = mergeOptions(media);
|
this.cache_.media = merge(media);
|
||||||
|
|
||||||
const {artwork, poster, src, textTracks} = this.cache_.media;
|
const {artwork, poster, src, textTracks} = this.cache_.media;
|
||||||
|
|
||||||
@ -5001,7 +4999,7 @@ class Player extends Component {
|
|||||||
return media;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeOptions(this.cache_.media);
|
return merge(this.cache_.media);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import window from 'global/window';
|
import window from 'global/window';
|
||||||
import { debounce } from './utils/fn.js';
|
import { debounce } from './utils/fn.js';
|
||||||
import * as Events from './utils/events.js';
|
import * as Events from './utils/events.js';
|
||||||
import mergeOptions from './utils/merge-options.js';
|
import {merge} from './utils/obj.js';
|
||||||
import Component from './component.js';
|
import Component from './component.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +47,7 @@ class ResizeManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only create an element when ResizeObserver isn't available
|
// Only create an element when ResizeObserver isn't available
|
||||||
const options_ = mergeOptions({
|
const options_ = merge({
|
||||||
createEl: !RESIZE_OBSERVER_AVAILABLE,
|
createEl: !RESIZE_OBSERVER_AVAILABLE,
|
||||||
reportTouchActivity: false
|
reportTouchActivity: false
|
||||||
}, options);
|
}, options);
|
||||||
|
@ -8,8 +8,7 @@ import log from '../utils/log.js';
|
|||||||
import * as browser from '../utils/browser.js';
|
import * as browser from '../utils/browser.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
import window from 'global/window';
|
import window from 'global/window';
|
||||||
import {assign} from '../utils/obj';
|
import {assign, merge} from '../utils/obj';
|
||||||
import mergeOptions from '../utils/merge-options.js';
|
|
||||||
import {toTitleCase} from '../utils/str.js';
|
import {toTitleCase} from '../utils/str.js';
|
||||||
import {NORMAL as TRACK_TYPES, REMOTE} from '../tracks/track-types';
|
import {NORMAL as TRACK_TYPES, REMOTE} from '../tracks/track-types';
|
||||||
import setupSourceset from './setup-sourceset';
|
import setupSourceset from './setup-sourceset';
|
||||||
@ -385,7 +384,7 @@ class Html5 extends Tech {
|
|||||||
|
|
||||||
// determine if native controls should be used
|
// determine if native controls should be used
|
||||||
const tagAttributes = this.options_.tag && Dom.getAttributes(this.options_.tag);
|
const tagAttributes = this.options_.tag && Dom.getAttributes(this.options_.tag);
|
||||||
const attributes = mergeOptions({}, tagAttributes);
|
const attributes = merge({}, tagAttributes);
|
||||||
|
|
||||||
if (!browser.TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
|
if (!browser.TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
|
||||||
delete attributes.controls;
|
delete attributes.controls;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import Component from '../component.js';
|
import Component from '../component.js';
|
||||||
import Tech from './tech.js';
|
import Tech from './tech.js';
|
||||||
import {toTitleCase} from '../utils/str.js';
|
import {toTitleCase} from '../utils/str.js';
|
||||||
import mergeOptions from '../utils/merge-options.js';
|
import {merge} from '../utils/obj.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `MediaLoader` is the `Component` that decides which playback technology to load
|
* The `MediaLoader` is the `Component` that decides which playback technology to load
|
||||||
@ -28,7 +28,7 @@ class MediaLoader extends Component {
|
|||||||
*/
|
*/
|
||||||
constructor(player, options, ready) {
|
constructor(player, options, ready) {
|
||||||
// MediaLoader has no element
|
// MediaLoader has no element
|
||||||
const options_ = mergeOptions({createEl: false}, options);
|
const options_ = merge({createEl: false}, options);
|
||||||
|
|
||||||
super(player, options_, ready);
|
super(player, options_, ready);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import window from 'global/window';
|
import window from 'global/window';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
import mergeOptions from '../utils/merge-options';
|
import {merge} from '../utils/obj';
|
||||||
import {getAbsoluteURL} from '../utils/url';
|
import {getAbsoluteURL} from '../utils/url';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,7 +183,7 @@ const firstSourceWatch = function(tech) {
|
|||||||
el[k] = appendWrapper(old[k]);
|
el[k] = appendWrapper(old[k]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
|
Object.defineProperty(el, 'innerHTML', merge(innerDescriptor, {
|
||||||
set: appendWrapper(innerDescriptor.set)
|
set: appendWrapper(innerDescriptor.set)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ const setupSourceset = function(tech) {
|
|||||||
const oldSetAttribute = el.setAttribute;
|
const oldSetAttribute = el.setAttribute;
|
||||||
const oldLoad = el.load;
|
const oldLoad = el.load;
|
||||||
|
|
||||||
Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
|
Object.defineProperty(el, 'src', merge(srcDescriptor, {
|
||||||
set: (v) => {
|
set: (v) => {
|
||||||
const retval = srcDescriptor.set.call(el, v);
|
const retval = srcDescriptor.set.call(el, v);
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Component from '../component';
|
import Component from '../component';
|
||||||
import mergeOptions from '../utils/merge-options.js';
|
|
||||||
import * as Fn from '../utils/fn.js';
|
import * as Fn from '../utils/fn.js';
|
||||||
import log from '../utils/log.js';
|
import log from '../utils/log.js';
|
||||||
import { createTimeRange } from '../utils/time-ranges.js';
|
import { createTimeRange } from '../utils/time-ranges.js';
|
||||||
@ -11,7 +10,7 @@ import { bufferedPercent } from '../utils/buffer.js';
|
|||||||
import MediaError from '../media-error.js';
|
import MediaError from '../media-error.js';
|
||||||
import window from 'global/window';
|
import window from 'global/window';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
import {isPlain} from '../utils/obj';
|
import {isPlain, merge} from '../utils/obj';
|
||||||
import * as TRACK_TYPES from '../tracks/track-types';
|
import * as TRACK_TYPES from '../tracks/track-types';
|
||||||
import {toTitleCase, toLowerCase} from '../utils/str.js';
|
import {toTitleCase, toLowerCase} from '../utils/str.js';
|
||||||
import vtt from 'videojs-vtt.js';
|
import vtt from 'videojs-vtt.js';
|
||||||
@ -743,7 +742,7 @@ class Tech extends Component {
|
|||||||
* The track element that gets created.
|
* The track element that gets created.
|
||||||
*/
|
*/
|
||||||
createRemoteTextTrack(options) {
|
createRemoteTextTrack(options) {
|
||||||
const track = mergeOptions(options, {
|
const track = merge(options, {
|
||||||
tech: this
|
tech: this
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {AudioTrackKind} from './track-enums';
|
import {AudioTrackKind} from './track-enums';
|
||||||
import Track from './track';
|
import Track from './track';
|
||||||
import merge from '../utils/merge-options';
|
import {merge} from '../utils/obj';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList}
|
* A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList}
|
||||||
|
@ -9,7 +9,7 @@ import window from 'global/window';
|
|||||||
import Track from './track.js';
|
import Track from './track.js';
|
||||||
import { isCrossOrigin } from '../utils/url.js';
|
import { isCrossOrigin } from '../utils/url.js';
|
||||||
import XHR from '@videojs/xhr';
|
import XHR from '@videojs/xhr';
|
||||||
import merge from '../utils/merge-options';
|
import {merge} from '../utils/obj';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a webvtt file contents and parses it into cues
|
* Takes a webvtt file contents and parses it into cues
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {VideoTrackKind} from './track-enums';
|
import {VideoTrackKind} from './track-enums';
|
||||||
import Track from './track';
|
import Track from './track';
|
||||||
import merge from '../utils/merge-options';
|
import {merge} from '../utils/obj';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of a single `VideoTrack`.
|
* A representation of a single `VideoTrack`.
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file merge-options.js
|
|
||||||
* @module merge-options
|
|
||||||
*/
|
|
||||||
import {merge} from './obj';
|
|
||||||
|
|
||||||
export default merge;
|
|
@ -109,7 +109,6 @@ const normalizeId = (id) => id.indexOf('#') === 0 ? id.slice(1) : id;
|
|||||||
* @borrows module:format-time.formatTime as formatTime
|
* @borrows module:format-time.formatTime as formatTime
|
||||||
* @borrows module:format-time.resetFormatTime as resetFormatTime
|
* @borrows module:format-time.resetFormatTime as resetFormatTime
|
||||||
* @borrows module:format-time.setFormatTime as setFormatTime
|
* @borrows module:format-time.setFormatTime as setFormatTime
|
||||||
* @borrows module:merge-options.mergeOptions as mergeOptions
|
|
||||||
* @borrows module:middleware.use as use
|
* @borrows module:middleware.use as use
|
||||||
* @borrows Player.players as players
|
* @borrows Player.players as players
|
||||||
* @borrows Plugin.registerPlugin as registerPlugin
|
* @borrows Plugin.registerPlugin as registerPlugin
|
||||||
|
@ -208,8 +208,6 @@ QUnit.test('should export useful components to the public', function(assert) {
|
|||||||
assert.ok(videojs.getComponent('ChaptersButton'), 'ChaptersButton should be public');
|
assert.ok(videojs.getComponent('ChaptersButton'), 'ChaptersButton should be public');
|
||||||
assert.ok(videojs.getComponent('ChaptersTrackMenuItem'),
|
assert.ok(videojs.getComponent('ChaptersTrackMenuItem'),
|
||||||
'ChaptersTrackMenuItem should be public');
|
'ChaptersTrackMenuItem should be public');
|
||||||
|
|
||||||
assert.ok(videojs.mergeOptions, 'mergeOptions should be public');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should be able to initialize player twice on the same tag using string reference', function(assert) {
|
QUnit.test('should be able to initialize player twice on the same tag using string reference', function(assert) {
|
||||||
|
@ -63,7 +63,7 @@ QUnit.module('autoplay', {
|
|||||||
videoTag.setAttribute(a, attributes[a]);
|
videoTag.setAttribute(a, attributes[a]);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player = videojs(videoTag.id, videojs.mergeOptions({techOrder: ['techFaker']}, options));
|
this.player = videojs(videoTag.id, videojs.obj.merge({techOrder: ['techFaker']}, options));
|
||||||
const oldMuted = this.player.muted;
|
const oldMuted = this.player.muted;
|
||||||
|
|
||||||
this.player.play = () => {
|
this.player.play = () => {
|
||||||
|
@ -51,7 +51,7 @@ const mainModule = function(playReturnValue, middlewareTermination, subhooks) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.checkState = (assertName, options = {}) => {
|
this.checkState = (assertName, options = {}) => {
|
||||||
const expectedState = videojs.mergeOptions({
|
const expectedState = videojs.obj.merge({
|
||||||
playCalls: 0,
|
playCalls: 0,
|
||||||
techLoaded: false,
|
techLoaded: false,
|
||||||
techReady: false,
|
techReady: false,
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
/* eslint-env qunit */
|
|
||||||
import mergeOptions from '../../../src/js/utils/merge-options.js';
|
|
||||||
|
|
||||||
QUnit.module('merge-options');
|
|
||||||
|
|
||||||
QUnit.test('should merge options objects', function(assert) {
|
|
||||||
const ob1 = {
|
|
||||||
a: true,
|
|
||||||
b: { b1: true, b2: true, b3: true },
|
|
||||||
c: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const ob2 = {
|
|
||||||
// override value
|
|
||||||
a: false,
|
|
||||||
// merge sub-option values
|
|
||||||
b: { b1: true, b2: false, b4: true },
|
|
||||||
// add new option
|
|
||||||
d: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const ob3 = mergeOptions(ob1, ob2);
|
|
||||||
|
|
||||||
assert.deepEqual(ob3, {
|
|
||||||
a: false,
|
|
||||||
b: { b1: true, b2: false, b3: true, b4: true },
|
|
||||||
c: true,
|
|
||||||
d: true
|
|
||||||
}, 'options objects merged correctly');
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('should ignore non-objects', function(assert) {
|
|
||||||
const obj = { a: 1 };
|
|
||||||
|
|
||||||
assert.deepEqual(mergeOptions(obj, true), obj, 'ignored non-object input');
|
|
||||||
});
|
|
@ -1,6 +1,6 @@
|
|||||||
/* eslint-env qunit */
|
/* eslint-env qunit */
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import * as Obj from '../../../src/js/utils/obj';
|
import * as obj from '../../../src/js/utils/obj';
|
||||||
|
|
||||||
QUnit.module('utils/obj');
|
QUnit.module('utils/obj');
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ const passFail = (assert, fn, descriptor, passes, failures) => {
|
|||||||
QUnit.test('each', function(assert) {
|
QUnit.test('each', function(assert) {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
Obj.each({
|
obj.each({
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 'foo',
|
b: 'foo',
|
||||||
c: null
|
c: null
|
||||||
@ -35,12 +35,12 @@ QUnit.test('each', function(assert) {
|
|||||||
assert.ok(spy.calledWith('foo', 'b'));
|
assert.ok(spy.calledWith('foo', 'b'));
|
||||||
assert.ok(spy.calledWith(null, 'c'));
|
assert.ok(spy.calledWith(null, 'c'));
|
||||||
|
|
||||||
Obj.each({}, spy);
|
obj.each({}, spy);
|
||||||
assert.strictEqual(spy.callCount, 3, 'an empty object was not iterated over');
|
assert.strictEqual(spy.callCount, 3, 'an empty object was not iterated over');
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('reduce', function(assert) {
|
QUnit.test('reduce', function(assert) {
|
||||||
const first = Obj.reduce({
|
const first = obj.reduce({
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 2,
|
b: 2,
|
||||||
c: 3,
|
c: 3,
|
||||||
@ -49,7 +49,7 @@ QUnit.test('reduce', function(assert) {
|
|||||||
|
|
||||||
assert.strictEqual(first, 10);
|
assert.strictEqual(first, 10);
|
||||||
|
|
||||||
const second = Obj.reduce({
|
const second = obj.reduce({
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 2,
|
b: 2,
|
||||||
c: 3,
|
c: 3,
|
||||||
@ -58,7 +58,7 @@ QUnit.test('reduce', function(assert) {
|
|||||||
|
|
||||||
assert.strictEqual(second, 20);
|
assert.strictEqual(second, 20);
|
||||||
|
|
||||||
const third = Obj.reduce({
|
const third = obj.reduce({
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 2,
|
b: 2,
|
||||||
c: 3,
|
c: 3,
|
||||||
@ -75,7 +75,7 @@ QUnit.test('reduce', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('isObject', function(assert) {
|
QUnit.test('isObject', function(assert) {
|
||||||
passFail(assert, Obj.isObject, 'an object', {
|
passFail(assert, obj.isObject, 'an object', {
|
||||||
'plain object': {},
|
'plain object': {},
|
||||||
'constructed object': new Foo(),
|
'constructed object': new Foo(),
|
||||||
'array': [],
|
'array': [],
|
||||||
@ -91,7 +91,7 @@ QUnit.test('isObject', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('isPlain', function(assert) {
|
QUnit.test('isPlain', function(assert) {
|
||||||
passFail(assert, Obj.isPlain, 'a plain object', {
|
passFail(assert, obj.isPlain, 'a plain object', {
|
||||||
'plain object': {}
|
'plain object': {}
|
||||||
}, {
|
}, {
|
||||||
'constructed object': new Foo(),
|
'constructed object': new Foo(),
|
||||||
@ -134,21 +134,21 @@ QUnit.module('utils/obj.assign', function() {
|
|||||||
QUnit.test('override object', function(assert) {
|
QUnit.test('override object', function(assert) {
|
||||||
const foo = {foo: 'yellow'};
|
const foo = {foo: 'yellow'};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign(foo, {foo: 'blue'}), {foo: 'blue'}, 'Obj.assign should return overriden result');
|
assert.deepEqual(obj.assign(foo, {foo: 'blue'}), {foo: 'blue'}, 'obj.assign should return overriden result');
|
||||||
assert.deepEqual(foo, {foo: 'blue'}, 'foo should be modified directly');
|
assert.deepEqual(foo, {foo: 'blue'}, 'foo should be modified directly');
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('new object', function(assert) {
|
QUnit.test('new object', function(assert) {
|
||||||
const foo = {foo: 'yellow'};
|
const foo = {foo: 'yellow'};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign({}, foo, {foo: 'blue'}), {foo: 'blue'}, 'Obj.assign should return result');
|
assert.deepEqual(obj.assign({}, foo, {foo: 'blue'}), {foo: 'blue'}, 'obj.assign should return result');
|
||||||
assert.deepEqual(foo, {foo: 'yellow'}, 'foo should not be modified');
|
assert.deepEqual(foo, {foo: 'yellow'}, 'foo should not be modified');
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('empty override', function(assert) {
|
QUnit.test('empty override', function(assert) {
|
||||||
const foo = {foo: 'yellow'};
|
const foo = {foo: 'yellow'};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign(foo, {}), {foo: 'yellow'}, 'Obj.assign should return result');
|
assert.deepEqual(obj.assign(foo, {}), {foo: 'yellow'}, 'obj.assign should return result');
|
||||||
assert.deepEqual(foo, {foo: 'yellow'}, 'foo should not be modified');
|
assert.deepEqual(foo, {foo: 'yellow'}, 'foo should not be modified');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ QUnit.module('utils/obj.assign', function() {
|
|||||||
const bar = {foo: 'bar'};
|
const bar = {foo: 'bar'};
|
||||||
const baz = {foo: 'baz'};
|
const baz = {foo: 'baz'};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign(foo, bar, baz), baz, 'Obj.assign should return result');
|
assert.deepEqual(obj.assign(foo, bar, baz), baz, 'obj.assign should return result');
|
||||||
assert.deepEqual(foo, baz, 'foo should be overridden');
|
assert.deepEqual(foo, baz, 'foo should be overridden');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ QUnit.module('utils/obj.assign', function() {
|
|||||||
const foo = {};
|
const foo = {};
|
||||||
const expected = {one: 1, two: 2, three: 3};
|
const expected = {one: 1, two: 2, three: 3};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign(foo, {one: 1}, {two: 2}, {three: 3}), expected, 'Obj.assign should return result');
|
assert.deepEqual(obj.assign(foo, {one: 1}, {two: 2}, {three: 3}), expected, 'obj.assign should return result');
|
||||||
assert.deepEqual(foo, expected, 'foo should be equal to result');
|
assert.deepEqual(foo, expected, 'foo should be equal to result');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,23 +199,55 @@ QUnit.module('utils/obj.assign', function() {
|
|||||||
red: 'nope'
|
red: 'nope'
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign(foo, baz), expected, 'Obj.assign should return result');
|
assert.deepEqual(obj.assign(foo, baz), expected, 'obj.assign should return result');
|
||||||
assert.deepEqual(foo, expected, 'foo is overridden');
|
assert.deepEqual(foo, expected, 'foo is overridden');
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('negative tests', function(assert) {
|
QUnit.test('negative tests', function(assert) {
|
||||||
const expected = {foo: 11};
|
const expected = {foo: 11};
|
||||||
|
|
||||||
assert.deepEqual(Obj.assign({}, expected, undefined), expected, 'assign should undefined');
|
assert.deepEqual(obj.assign({}, expected, undefined), expected, 'assign should undefined');
|
||||||
assert.deepEqual(Obj.assign({}, expected, null), expected, 'assign should ignore null');
|
assert.deepEqual(obj.assign({}, expected, null), expected, 'assign should ignore null');
|
||||||
assert.deepEqual(Obj.assign({}, expected, []), expected, 'assign should ignore Array');
|
assert.deepEqual(obj.assign({}, expected, []), expected, 'assign should ignore Array');
|
||||||
assert.deepEqual(Obj.assign({}, expected, ''), expected, 'assign should ignore string');
|
assert.deepEqual(obj.assign({}, expected, ''), expected, 'assign should ignore string');
|
||||||
assert.deepEqual(Obj.assign({}, expected, 11), expected, 'assign should ignore number');
|
assert.deepEqual(obj.assign({}, expected, 11), expected, 'assign should ignore number');
|
||||||
assert.deepEqual(Obj.assign({}, expected, new RegExp()), expected, 'assign should ignore RegExp');
|
assert.deepEqual(obj.assign({}, expected, new RegExp()), expected, 'assign should ignore RegExp');
|
||||||
assert.deepEqual(Obj.assign({}, expected, new Date()), expected, 'assign should ignore Date');
|
assert.deepEqual(obj.assign({}, expected, new Date()), expected, 'assign should ignore Date');
|
||||||
assert.deepEqual(Obj.assign({}, expected, true), expected, 'assign should ignore boolean');
|
assert.deepEqual(obj.assign({}, expected, true), expected, 'assign should ignore boolean');
|
||||||
assert.deepEqual(Obj.assign({}, expected, () => {}), expected, 'assign should ignore function');
|
assert.deepEqual(obj.assign({}, expected, () => {}), expected, 'assign should ignore function');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('utils/obj.merge', function(assert) {
|
||||||
|
const ob1 = {
|
||||||
|
a: true,
|
||||||
|
b: {b1: true, b2: true, b3: true},
|
||||||
|
c: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const ob2 = {
|
||||||
|
// override value
|
||||||
|
a: false,
|
||||||
|
// merge sub-option values
|
||||||
|
b: { b1: true, b2: false, b4: true },
|
||||||
|
// add new option
|
||||||
|
d: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const ob3 = obj.merge(ob1, ob2);
|
||||||
|
|
||||||
|
assert.deepEqual(ob3, {
|
||||||
|
a: false,
|
||||||
|
b: {b1: true, b2: false, b3: true, b4: true},
|
||||||
|
c: true,
|
||||||
|
d: true
|
||||||
|
}, 'options objects merged correctly');
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('utils/obj.merge: should ignore non-objects', function(assert) {
|
||||||
|
const target = {a: 1};
|
||||||
|
|
||||||
|
assert.deepEqual(obj.merge(target, true), target, 'ignored non-object input');
|
||||||
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user