Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from wmcmurray/lodash-optimization
Browse files Browse the repository at this point in the history
Lodash optimization
  • Loading branch information
wangpin87 authored Feb 6, 2018
2 parents 2fc3402 + d3887f6 commit 00e55d3
Show file tree
Hide file tree
Showing 8 changed files with 752 additions and 17,125 deletions.
15 changes: 11 additions & 4 deletions build/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function genConfig (opts) {
// set this to `false` if you don't want to
// remove debugger statements
debugger: true,

// defaults to `[ 'console.*', 'assert.*' ]`
functions: [ 'console.log', 'assert.*', 'debug', 'alert' ],

// set this to `false` if you're not using sourcemaps –
// defaults to `true`
sourceMap: true
Expand All @@ -76,8 +76,15 @@ function genConfig (opts) {
'process.env.NODE_ENV': JSON.stringify(opts.env)
}))
} else {
config.input.external = [ 'lodash' ]
config.input.external = [
'lodash/isObject',
'lodash/isFunction',
'lodash/isInteger',
'lodash/isFinite',
'lodash/debounce',
'lodash/throttle',
]
}

return config
}
}
9 changes: 7 additions & 2 deletions build/rollup.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export default {
format: 'cjs'
},
external: [
'lodash'
'lodash/isObject',
'lodash/isFunction',
'lodash/isInteger',
'lodash/isFinite',
'lodash/debounce',
'lodash/throttle',
]
}
}
45 changes: 25 additions & 20 deletions dist/vue-scroll.common.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/**
* vue-scroll v2.1.6
* (c) 2017 Wang Pin
* (c) 2018 Wang Pin
* @license MIT
*/
'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var _ = _interopDefault(require('lodash'));
var _isObject = _interopDefault(require('lodash/isObject'));
var _isFunction = _interopDefault(require('lodash/isFunction'));
var _isInteger = _interopDefault(require('lodash/isInteger'));
var _isFinite = _interopDefault(require('lodash/isFinite'));
var _debounce = _interopDefault(require('lodash/debounce'));
var _throttle = _interopDefault(require('lodash/throttle'));

var dom = (function () {
var listeners = new Map();
Expand All @@ -20,7 +25,7 @@ var dom = (function () {
var data;
var target = e.target || e.srcElement;
e = e || window.e;

if (e.type === SCROLL) {
if (target === document) {
data = { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft };
Expand All @@ -34,16 +39,16 @@ var dom = (function () {
});
}

if (_.isObject(opt)) {
if (_.isInteger(opt.throttle) && _.isFinite(opt.throttle) && opt.throttle > -1) {
fn = _.throttle(fn, opt.throttle);
if (_isObject(opt)) {
if (_isInteger(opt.throttle) && _isFinite(opt.throttle) && opt.throttle > -1) {
fn = _throttle(fn, opt.throttle);
}

if (_.isInteger(opt.debounce) && _.isFinite(opt.debounce) && opt.debounce > -1) {
fn = _.debounce(fn, opt.debounce);
if (_isInteger(opt.debounce) && _isFinite(opt.debounce) && opt.debounce > -1) {
fn = _debounce(fn, opt.debounce);
}
}

// https://github.com/wangpin34/vue-scroll/issues/1
if (event === SCROLL) {
if(element === document.body || element === document || element === window) {
Expand All @@ -58,22 +63,22 @@ var dom = (function () {
}

}


function bind (element, event, fn, opt) {

var funcs, eventFuncs;

if (!_.isFunction(fn)) {
if (!_isFunction(fn)) {
throw new Error('Scroll handler is not a function');
}

if (!listeners.has(element)) {
listeners.set(element, new Map());
}

funcs = listeners.get(element);

if (!funcs.has(event)) {
funcs.set(event, []);
}
Expand All @@ -83,7 +88,7 @@ var dom = (function () {
if (!eventFuncs.length) {
addEventListener(element, event, eventFuncs, opt);
}

eventFuncs.push(fn);

}
Expand All @@ -92,7 +97,7 @@ var dom = (function () {

var funcs, eventFuncs;

if (!_.isFunction(fn)) {
if (!_isFunction(fn)) {
return;
}

Expand All @@ -101,7 +106,7 @@ var dom = (function () {
}

funcs = listeners.get(element);

if (!funcs.has(event)) {
funcs.set(event, []);
}
Expand Down Expand Up @@ -136,7 +141,7 @@ vuescroll.install = function (Vue, options) {

function bindValue (el, value, arg) {
var fn, opt = Object.assign({}, options);
if (_.isObject(value) || _.isFunction(value)) {
if (_isObject(value) || _isFunction(value)) {
fn = value;

if (VALID_ARGS.indexOf(arg) > -1) {
Expand All @@ -153,15 +158,15 @@ vuescroll.install = function (Vue, options) {
} catch(err) {
console.warn('Unexpected error happened when binding listener');
}

} else {
console.warn('Unexpected scroll properties');
}
}

function unbindValue (el, value, arg) {
var fn;
if (_.isObject(value) || _.isFunction(value)) {
if (_isObject(value) || _isFunction(value)) {
fn = value;
if (VALID_ARGS.indexOf(arg) > -1) {
fn = value.fn;
Expand Down
45 changes: 25 additions & 20 deletions dist/vue-scroll.esm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* vue-scroll v2.1.6
* (c) 2017 Wang Pin
* (c) 2018 Wang Pin
* @license MIT
*/
import _ from 'lodash';
import _isObject from 'lodash/isObject';
import _isFunction from 'lodash/isFunction';
import _isInteger from 'lodash/isInteger';
import _isFinite from 'lodash/isFinite';
import _debounce from 'lodash/debounce';
import _throttle from 'lodash/throttle';

var dom = (function () {
var listeners = new Map();
Expand All @@ -16,7 +21,7 @@ var dom = (function () {
var data;
var target = e.target || e.srcElement;
e = e || window.e;

if (e.type === SCROLL) {
if (target === document) {
data = { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft };
Expand All @@ -30,16 +35,16 @@ var dom = (function () {
});
}

if (_.isObject(opt)) {
if (_.isInteger(opt.throttle) && _.isFinite(opt.throttle) && opt.throttle > -1) {
fn = _.throttle(fn, opt.throttle);
if (_isObject(opt)) {
if (_isInteger(opt.throttle) && _isFinite(opt.throttle) && opt.throttle > -1) {
fn = _throttle(fn, opt.throttle);
}

if (_.isInteger(opt.debounce) && _.isFinite(opt.debounce) && opt.debounce > -1) {
fn = _.debounce(fn, opt.debounce);
if (_isInteger(opt.debounce) && _isFinite(opt.debounce) && opt.debounce > -1) {
fn = _debounce(fn, opt.debounce);
}
}

// https://github.com/wangpin34/vue-scroll/issues/1
if (event === SCROLL) {
if(element === document.body || element === document || element === window) {
Expand All @@ -54,22 +59,22 @@ var dom = (function () {
}

}


function bind (element, event, fn, opt) {

var funcs, eventFuncs;

if (!_.isFunction(fn)) {
if (!_isFunction(fn)) {
throw new Error('Scroll handler is not a function');
}

if (!listeners.has(element)) {
listeners.set(element, new Map());
}

funcs = listeners.get(element);

if (!funcs.has(event)) {
funcs.set(event, []);
}
Expand All @@ -79,7 +84,7 @@ var dom = (function () {
if (!eventFuncs.length) {
addEventListener(element, event, eventFuncs, opt);
}

eventFuncs.push(fn);

}
Expand All @@ -88,7 +93,7 @@ var dom = (function () {

var funcs, eventFuncs;

if (!_.isFunction(fn)) {
if (!_isFunction(fn)) {
return;
}

Expand All @@ -97,7 +102,7 @@ var dom = (function () {
}

funcs = listeners.get(element);

if (!funcs.has(event)) {
funcs.set(event, []);
}
Expand Down Expand Up @@ -132,7 +137,7 @@ vuescroll.install = function (Vue, options) {

function bindValue (el, value, arg) {
var fn, opt = Object.assign({}, options);
if (_.isObject(value) || _.isFunction(value)) {
if (_isObject(value) || _isFunction(value)) {
fn = value;

if (VALID_ARGS.indexOf(arg) > -1) {
Expand All @@ -149,15 +154,15 @@ vuescroll.install = function (Vue, options) {
} catch(err) {
console.warn('Unexpected error happened when binding listener');
}

} else {
console.warn('Unexpected scroll properties');
}
}

function unbindValue (el, value, arg) {
var fn;
if (_.isObject(value) || _.isFunction(value)) {
if (_isObject(value) || _isFunction(value)) {
fn = value;
if (VALID_ARGS.indexOf(arg) > -1) {
fn = value.fn;
Expand Down
Loading

0 comments on commit 00e55d3

Please sign in to comment.