Skip to content

Commit

Permalink
Convert several lodash functions to internal utils
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner committed May 3, 2019
1 parent 75e78cd commit 2c0f648
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 62 deletions.
8 changes: 6 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = function(api) {
[
'@babel/preset-env',
{
modules: false
corejs: 3,
modules: false,
useBuiltIns: 'entry'
}
]
],
Expand All @@ -16,7 +18,9 @@ module.exports = function(api) {
[
'@babel/preset-env',
{
modules: false
corejs: 3,
modules: false,
useBuiltIns: 'entry'
}
]
],
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@
"dependencies": {
"element-matches": "^0.1.2",
"lodash.defer": "^4.1.0",
"lodash.forown": "^4.4.0",
"lodash.iselement": "^4.1.1",
"lodash.isfunction": "^3.0.9",
"lodash.isnumber": "^3.0.3",
"lodash.isobjectlike": "^4.0.0",
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1",
"lodash.zipobject": "^4.1.3",
"tippy.js": "^4.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/js/evented.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { drop } from './utils/general';
import isUndefined from 'lodash.isundefined';
import { isUndefined } from './utils/type-check';

export class Evented {
on(event, handler, ctx) {
Expand Down
15 changes: 7 additions & 8 deletions src/js/step.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import forOwn from 'lodash.forown';
import isElement from 'lodash.iselement';
import isFunction from 'lodash.isfunction';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import { isFunction, isString, isUndefined } from './utils/type-check';
import { Evented } from './evented.js';
import 'element-matches';
import { bindAdvance, bindButtonEvents, bindCancelLink, bindMethods } from './utils/bind.js';
Expand Down Expand Up @@ -51,7 +48,7 @@ export class Step extends Evented {
* @param {string} options.attachTo.on
* @param {Object|string} options.advanceOn An action on the page which should advance shepherd to the next step.
* It can be of the form `"selector event"`:
* ```js
* ```js
* const new Step(tour, {
* advanceOn: '.some .selector-path click',
* ...moreOptions
Expand Down Expand Up @@ -362,9 +359,11 @@ export class Step extends Evented {
this.destroy();
this.id = this.options.id || `step-${uniqueId()}`;

forOwn(when, (handler, event) => {
this.on(event, handler, this);
});
if (when) {
Object.entries(when).forEach(([event, handler]) => {
this.on(event, handler, this);
});
}
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/js/tour.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import isFunction from 'lodash.isfunction';
import isNumber from 'lodash.isnumber';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import { isFunction, isNumber, isString, isUndefined } from './utils/type-check';
import { Evented } from './evented.js';
import { Modal } from './modal.js';
import { Step } from './step.js';
Expand Down
30 changes: 15 additions & 15 deletions src/js/utils/bind.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { parseShorthand } from './general.js';
import forOwn from 'lodash.forown';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import { isString, isUndefined } from './type-check';

/**
* Sets up the handler to determine if we should advance the tour
Expand Down Expand Up @@ -52,20 +50,22 @@ export function bindButtonEvents(cfg, el) {
cfg.events.click = cfg.action;
}

forOwn(cfg.events, (handler, event) => {
if (isString(handler)) {
const page = handler;
handler = () => this.tour.show(page);
}
el.dataset.buttonEvent = true;
el.addEventListener(event, handler);
if (cfg.events) {
Object.entries(cfg.events).forEach(([event, handler]) => {
if (isString(handler)) {
const page = handler;
handler = () => this.tour.show(page);
}
el.dataset.buttonEvent = true;
el.addEventListener(event, handler);

// Cleanup event listeners on destroy
this.on('destroy', () => {
el.removeAttribute('data-button-event');
el.removeEventListener(event, handler);
// Cleanup event listeners on destroy
this.on('destroy', () => {
el.removeAttribute('data-button-event');
el.removeEventListener(event, handler);
});
});
});
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/js/utils/general.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import isObjectLike from 'lodash.isobjectlike';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import { isString, isUndefined } from './type-check';
import zipObject from 'lodash.zipobject';
import tippy from 'tippy.js';
import { missingTippy } from './error-messages';
Expand Down
31 changes: 31 additions & 0 deletions src/js/utils/type-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Checks if `value` is classified as a `Function` object.
* @param {*} value The param to check if it is a function
*/
export function isFunction(value) {
return typeof value === 'function';
}

/**
* Checks if `value` is classified as a `Number` object.
* @param {*} value The param to check if it is a number
*/
export function isNumber(value) {
return typeof value === 'number';
}

/**
* Checks if `value` is classified as a `String` object.
* @param {*} value The param to check if it is a string
*/
export function isString(value) {
return typeof value === 'string';
}

/**
* Checks if `value` is undefined.
* @param {*} value The param to check if it is undefined
*/
export function isUndefined(value) {
return value === undefined;
}
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5830,11 +5830,6 @@ lodash.foreach@^4.3.0:
resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53"
integrity sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM=

lodash.forown@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.forown/-/lodash.forown-4.4.0.tgz#85115cf04f73ef966eced52511d3893cc46683af"
integrity sha1-hRFc8E9z75ZuztUlEdOJPMRmg68=

lodash.iselement@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.iselement/-/lodash.iselement-4.1.1.tgz#f678d4f6f3a964f9ec7f115f2546f3e4a0ba82ca"
Expand All @@ -5845,31 +5840,11 @@ lodash.isfinite@^3.3.2:
resolved "https://registry.yarnpkg.com/lodash.isfinite/-/lodash.isfinite-3.3.2.tgz#fb89b65a9a80281833f0b7478b3a5104f898ebb3"
integrity sha1-+4m2WpqAKBgz8LdHizpRBPiY67M=

lodash.isfunction@^3.0.9:
version "3.0.9"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==

lodash.isnumber@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"
integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=

lodash.isobjectlike@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isobjectlike/-/lodash.isobjectlike-4.0.0.tgz#742c5fc65add27924d3d24191681aa9a17b2b60d"
integrity sha1-dCxfxlrdJ5JNPSQZFoGqmheytg0=

lodash.isstring@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=

lodash.isundefined@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash.isundefined/-/lodash.isundefined-3.0.1.tgz#23ef3d9535565203a66cefd5b830f848911afb48"
integrity sha1-I+89lTVWUgOmbO/VuDD4SJEa+0g=

lodash.map@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
Expand Down

0 comments on commit 2c0f648

Please sign in to comment.