From 865e946e2dca2964b4266c3c629cc5151d8c28f9 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 12 Aug 2021 13:38:35 +0200 Subject: [PATCH] Update Devices docs --- src/device_manager/index.js | 48 ++++++++----------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/device_manager/index.js b/src/device_manager/index.js index 9617856db..3279982e9 100644 --- a/src/device_manager/index.js +++ b/src/device_manager/index.js @@ -25,38 +25,15 @@ import Devices from './model/Devices'; import DevicesView from './view/DevicesView'; export default () => { - var c = {}; - var devices, view; + let c = {}; + let devices; + let view; return { - /** - * Name of the module - * @type {String} - * @private - */ name: 'DeviceManager', - /** - * Initialize module. Automatically called with a new instance of the editor - * @param {Object} config Configurations - * @param {Array} [config.devices=[]] Default devices - * @example - * ... - * { - * devices: [ - * {name: 'Desktop', width: ''} - * {name: 'Tablet', width: '991px'} - * ], - * } - * ... - * @return {this} - * @private - */ - init(config) { - c = config || {}; - for (var name in defaults) { - if (!(name in c)) c[name] = defaults[name]; - } + init(config = {}) { + c = { ...defaults, ...config }; devices = new Devices(); (c.devices || []).forEach(dv => this.add(dv.id || dv.name, dv.width, dv)); @@ -65,10 +42,10 @@ export default () => { }, /** - * Add new device to the collection. URLs are supposed to be unique + * Add new device. * @param {String} id Device id * @param {String} width Width of the device - * @param {Object} [opts] Custom options + * @param {Object} [options] Custom options * @returns {Device} Added device * @example * deviceManager.add('tablet', '900px'); @@ -80,11 +57,11 @@ export default () => { * widthMedia: '810px', // the width that will be used for the CSS media * }); */ - add(id, width, opts = {}) { + add(id, width, options = {}) { const obj = { - ...opts, + ...options, id, - name: opts.name || id, + name: options.name || id, width: width }; return devices.add(obj); @@ -114,11 +91,6 @@ export default () => { return devices; }, - /** - * Render devices - * @return {string} HTML string - * @private - */ render() { view && view.remove(); view = new DevicesView({