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

Remove drop util #436

Merged
merged 1 commit into from
Jul 15, 2019
Merged
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
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = function(api) {
]
],
plugins: [
'rewire-exports',
'transform-es2015-modules-commonjs'
]
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"autoprefixer": "^9.6.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.7.1",
"babel-plugin-rewire-exports": "^1.2.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"better-docs": "^1.1.6",
"chai": "^4.2.0",
Expand Down
3 changes: 1 addition & 2 deletions src/js/evented.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { drop } from './utils/general';
import { isUndefined } from './utils/type-check';

export class Evented {
Expand Down Expand Up @@ -36,7 +35,7 @@ export class Evented {

trigger(event) {
if (!isUndefined(this.bindings) && this.bindings[event]) {
const args = drop(Array.prototype.slice.call(arguments));
const args = Array.prototype.slice.call(arguments, 1);

this.bindings[event].forEach((binding, index) => {
const { ctx, handler, once } = binding;
Expand Down
14 changes: 0 additions & 14 deletions src/js/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ export function debounce(func, wait, immediate) {
};
}

/**
* Creates a slice of `arr` with n elements dropped from the beginning.
* @param {Array} arr
* @param {Number} n
* @return {*}
*/
export function drop(arr, n = 1) {
if (Array.isArray(arr)) {
return arr.slice(n);
}

return [];
}

/**
* Determines options for the tooltip and initializes
* `this.tooltip` as a Tippy.js instance.
Expand Down
11 changes: 11 additions & 0 deletions test/unit/evented.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Evented } from '../../src/js/evented.js';
import { spy } from 'sinon';

describe('Evented', () => {
let testEvent, testOnTriggered;
Expand All @@ -20,6 +21,16 @@ describe('Evented', () => {
testEvent.trigger('testOn');
expect(testOnTriggered, 'true is returned from event trigger').toBeTruthy();
});

it('passes arguments to handler functions', () => {
const handlerSpy = spy();
testEvent.on('myEvent', handlerSpy);
testEvent.trigger('myEvent', {
step: { id: 'test', text: 'A step' },
previous: null
});
expect(handlerSpy.args).toEqual([[{ 'previous': null, 'step': { 'id': 'test', 'text': 'A step' } }]]);
});
});

describe('off()', () => {
Expand Down
18 changes: 0 additions & 18 deletions test/unit/tour.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Step } from '../../src/js/step.js';
import tippy from 'tippy.js';
import { defaults as tooltipDefaults } from '../../src/js/utils/tooltip-defaults';
import { spy } from 'sinon';
import { drop, rewire$drop, restore } from '../../src/js/utils/general';

// since importing non UMD, needs assignment
window.Shepherd = Shepherd;
Expand Down Expand Up @@ -380,14 +379,6 @@ describe('Tour | Top-Level Class', function() {
});

describe('.show()', function() {
let dropSpy;

beforeEach(() => {
rewire$drop(dropSpy = spy(drop));
});

afterEach(restore);

it('show short-circuits if next is not found', function() {
let showFired = false;
instance.start();
Expand All @@ -408,15 +399,6 @@ describe('Tour | Top-Level Class', function() {
shouldShowStep = true;
instance.next();
expect(instance.getCurrentStep().id, 'step shown because `showOn` returns true').toBe('skipped-step');

// This spy checks that, when we call `trigger` with `show`, that we pass `arguments` down.
const dropArguments = dropSpy.args[2][0];
const dropReturnValue = dropSpy.returnValues[2][0];
expect(dropArguments[0]).toBe('show');
expect(dropArguments[1].previous).toBe(null);
expect(dropArguments[1].step.id).toBe('test');
expect(dropReturnValue.previous).toBe(null);
expect(dropReturnValue.step.id).toBe('test');
});

it(`sets the instance on \`Shepherd.activeTour\` if it's not already set`, function() {
Expand Down
25 changes: 9 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,6 @@
dependencies:
regenerator-runtime "^0.13.2"

"@babel/template@7", "@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.4.tgz#f4b88d1225689a08f5bc3a17483545be9e4ed237"
integrity sha512-CiGzLN9KgAvgZsnivND7rkA+AeJ9JB0ciPOD4U59GKbQP2iQl+olF1l76kJOupqidozfZ32ghwBEJDhnk9MEcw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.4.4"
"@babel/types" "^7.4.4"

"@babel/template@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.44.tgz#f8832f4fdcee5d59bf515e595fc5106c529b394f"
Expand All @@ -688,6 +679,15 @@
babylon "7.0.0-beta.44"
lodash "^4.2.0"

"@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.4.tgz#f4b88d1225689a08f5bc3a17483545be9e4ed237"
integrity sha512-CiGzLN9KgAvgZsnivND7rkA+AeJ9JB0ciPOD4U59GKbQP2iQl+olF1l76kJOupqidozfZ32ghwBEJDhnk9MEcw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.4.4"
"@babel/types" "^7.4.4"

"@babel/traverse@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.44.tgz#a970a2c45477ad18017e2e465a0606feee0d2966"
Expand Down Expand Up @@ -1495,13 +1495,6 @@ babel-plugin-jest-hoist@^24.6.0:
dependencies:
"@types/babel__traverse" "^7.0.6"

babel-plugin-rewire-exports@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-rewire-exports/-/babel-plugin-rewire-exports-1.2.0.tgz#a1680b55cb1332cde38cf29e1e1fa317ef76ddcc"
integrity sha512-Y+WD3zUnCP2HDO2LnF9DUbeUXU0TYJ3MImhDDUfIcmBiHpBKlHcao8ieqVJwS4KqAoAWMLttaPF4Opsw+exSsw==
dependencies:
"@babel/template" "7"

babel-plugin-transform-es2015-modules-commonjs@^6.26.2:
version "6.26.2"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz#58a793863a9e7ca870bdc5a881117ffac27db6f3"
Expand Down