Browse Source

Refactoring.

NaotoshiFujita 3 years ago
parent
commit
f2de1cd5eb

File diff suppressed because it is too large
+ 0 - 0
dist/js/splide-renderer.min.js


+ 31 - 42
dist/js/splide.cjs.js

@@ -63,21 +63,37 @@ function empty(array) {
   array.length = 0;
 }
 
-function isObject(subject) {
-  return !isNull(subject) && typeof subject === "object";
+function slice(arrayLike, start, end) {
+  return Array.prototype.slice.call(arrayLike, start, end);
+}
+
+function find(arrayLike, predicate) {
+  return slice(arrayLike).filter(predicate)[0];
 }
-function isArray(subject) {
-  return Array.isArray(subject);
+
+function apply(func) {
+  return func.bind(null, ...slice(arguments, 1));
 }
-function isFunction(subject) {
-  return typeof subject === "function";
+
+const nextTick = setTimeout;
+
+const noop = () => {
+};
+
+function raf(func) {
+  return requestAnimationFrame(func);
 }
-function isString(subject) {
-  return typeof subject === "string";
+
+function typeOf(type, subject) {
+  return typeof subject === type;
 }
-function isUndefined(subject) {
-  return typeof subject === "undefined";
+function isObject(subject) {
+  return !isNull(subject) && typeOf("object", subject);
 }
+const isArray = Array.isArray;
+const isFunction = apply(typeOf, "function");
+const isString = apply(typeOf, "string");
+const isUndefined = apply(typeOf, "undefined");
 function isNull(subject) {
   return subject === null;
 }
@@ -102,16 +118,6 @@ function push(array, items) {
   return array;
 }
 
-const arrayProto = Array.prototype;
-
-function slice(arrayLike, start, end) {
-  return arrayProto.slice.call(arrayLike, start, end);
-}
-
-function find(arrayLike, predicate) {
-  return slice(arrayLike).filter(predicate)[0];
-}
-
 function toggleClass(elm, classes, add) {
   if (elm) {
     forEach(classes, (name) => {
@@ -311,19 +317,6 @@ function assert(condition, message) {
   }
 }
 
-function apply(func) {
-  return func.bind(null, ...slice(arguments, 1));
-}
-
-const nextTick = setTimeout;
-
-const noop = () => {
-};
-
-function raf(func) {
-  return requestAnimationFrame(func);
-}
-
 const { min, max, floor, ceil, abs } = Math;
 
 function approximatelyEqual(x, y, epsilon) {
@@ -370,19 +363,15 @@ function EventBus() {
   let handlers = {};
   function on(events, callback, key, priority = DEFAULT_EVENT_PRIORITY) {
     forEachEvent(events, (event, namespace) => {
-      handlers[event] = handlers[event] || [];
-      push(handlers[event], {
-        _callback: callback,
-        _namespace: namespace,
-        _priority: priority,
-        _key: key
-      }).sort((handler1, handler2) => handler1._priority - handler2._priority);
+      const events2 = handlers[event] = handlers[event] || [];
+      events2.push([callback, namespace, priority, key]);
+      events2.sort((handler1, handler2) => handler1[2] - handler2[2]);
     });
   }
   function off(events, key) {
     forEachEvent(events, (event, namespace) => {
       handlers[event] = (handlers[event] || []).filter((handler) => {
-        return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
+        return handler[3] ? handler[3] !== key : key || handler[1] !== namespace;
       });
     });
   }
@@ -393,7 +382,7 @@ function EventBus() {
   }
   function emit(event) {
     (handlers[event] || []).forEach((handler) => {
-      handler._callback.apply(handler, slice(arguments, 1));
+      handler[0].apply(handler, slice(arguments, 1));
     });
   }
   function destroy() {

+ 31 - 42
dist/js/splide.esm.js

@@ -59,21 +59,37 @@ function empty(array) {
   array.length = 0;
 }
 
-function isObject(subject) {
-  return !isNull(subject) && typeof subject === "object";
+function slice(arrayLike, start, end) {
+  return Array.prototype.slice.call(arrayLike, start, end);
+}
+
+function find(arrayLike, predicate) {
+  return slice(arrayLike).filter(predicate)[0];
 }
-function isArray(subject) {
-  return Array.isArray(subject);
+
+function apply(func) {
+  return func.bind(null, ...slice(arguments, 1));
 }
-function isFunction(subject) {
-  return typeof subject === "function";
+
+const nextTick = setTimeout;
+
+const noop = () => {
+};
+
+function raf(func) {
+  return requestAnimationFrame(func);
 }
-function isString(subject) {
-  return typeof subject === "string";
+
+function typeOf(type, subject) {
+  return typeof subject === type;
 }
-function isUndefined(subject) {
-  return typeof subject === "undefined";
+function isObject(subject) {
+  return !isNull(subject) && typeOf("object", subject);
 }
+const isArray = Array.isArray;
+const isFunction = apply(typeOf, "function");
+const isString = apply(typeOf, "string");
+const isUndefined = apply(typeOf, "undefined");
 function isNull(subject) {
   return subject === null;
 }
@@ -98,16 +114,6 @@ function push(array, items) {
   return array;
 }
 
-const arrayProto = Array.prototype;
-
-function slice(arrayLike, start, end) {
-  return arrayProto.slice.call(arrayLike, start, end);
-}
-
-function find(arrayLike, predicate) {
-  return slice(arrayLike).filter(predicate)[0];
-}
-
 function toggleClass(elm, classes, add) {
   if (elm) {
     forEach(classes, (name) => {
@@ -307,19 +313,6 @@ function assert(condition, message) {
   }
 }
 
-function apply(func) {
-  return func.bind(null, ...slice(arguments, 1));
-}
-
-const nextTick = setTimeout;
-
-const noop = () => {
-};
-
-function raf(func) {
-  return requestAnimationFrame(func);
-}
-
 const { min, max, floor, ceil, abs } = Math;
 
 function approximatelyEqual(x, y, epsilon) {
@@ -366,19 +359,15 @@ function EventBus() {
   let handlers = {};
   function on(events, callback, key, priority = DEFAULT_EVENT_PRIORITY) {
     forEachEvent(events, (event, namespace) => {
-      handlers[event] = handlers[event] || [];
-      push(handlers[event], {
-        _callback: callback,
-        _namespace: namespace,
-        _priority: priority,
-        _key: key
-      }).sort((handler1, handler2) => handler1._priority - handler2._priority);
+      const events2 = handlers[event] = handlers[event] || [];
+      events2.push([callback, namespace, priority, key]);
+      events2.sort((handler1, handler2) => handler1[2] - handler2[2]);
     });
   }
   function off(events, key) {
     forEachEvent(events, (event, namespace) => {
       handlers[event] = (handlers[event] || []).filter((handler) => {
-        return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
+        return handler[3] ? handler[3] !== key : key || handler[1] !== namespace;
       });
     });
   }
@@ -389,7 +378,7 @@ function EventBus() {
   }
   function emit(event) {
     (handlers[event] || []).forEach((handler) => {
-      handler._callback.apply(handler, slice(arguments, 1));
+      handler[0].apply(handler, slice(arguments, 1));
     });
   }
   function destroy() {

+ 29 - 42
dist/js/splide.js

@@ -66,26 +66,39 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     array.length = 0;
   }
 
-  function isObject(subject) {
-    return !isNull(subject) && typeof subject === "object";
+  function slice(arrayLike, start, end) {
+    return Array.prototype.slice.call(arrayLike, start, end);
   }
 
-  function isArray(subject) {
-    return Array.isArray(subject);
+  function find(arrayLike, predicate) {
+    return slice(arrayLike).filter(predicate)[0];
   }
 
-  function isFunction(subject) {
-    return typeof subject === "function";
+  function apply(func) {
+    return func.bind.apply(func, [null].concat(slice(arguments, 1)));
+  }
+
+  var nextTick = setTimeout;
+
+  var noop = function noop() {};
+
+  function raf(func) {
+    return requestAnimationFrame(func);
   }
 
-  function isString(subject) {
-    return typeof subject === "string";
+  function typeOf(type, subject) {
+    return typeof subject === type;
   }
 
-  function isUndefined(subject) {
-    return typeof subject === "undefined";
+  function isObject(subject) {
+    return !isNull(subject) && typeOf("object", subject);
   }
 
+  var isArray = Array.isArray;
+  var isFunction = apply(typeOf, "function");
+  var isString = apply(typeOf, "string");
+  var isUndefined = apply(typeOf, "undefined");
+
   function isNull(subject) {
     return subject === null;
   }
@@ -111,16 +124,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     return array;
   }
 
-  var arrayProto = Array.prototype;
-
-  function slice(arrayLike, start, end) {
-    return arrayProto.slice.call(arrayLike, start, end);
-  }
-
-  function find(arrayLike, predicate) {
-    return slice(arrayLike).filter(predicate)[0];
-  }
-
   function toggleClass(elm, classes, add) {
     if (elm) {
       forEach(classes, function (name) {
@@ -336,18 +339,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     }
   }
 
-  function apply(func) {
-    return func.bind.apply(func, [null].concat(slice(arguments, 1)));
-  }
-
-  var nextTick = setTimeout;
-
-  var noop = function noop() {};
-
-  function raf(func) {
-    return requestAnimationFrame(func);
-  }
-
   var min = Math.min,
       max = Math.max,
       floor = Math.floor,
@@ -400,14 +391,10 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       }
 
       forEachEvent(events, function (event, namespace) {
-        handlers[event] = handlers[event] || [];
-        push(handlers[event], {
-          _callback: callback,
-          _namespace: namespace,
-          _priority: priority,
-          _key: key
-        }).sort(function (handler1, handler2) {
-          return handler1._priority - handler2._priority;
+        var events2 = handlers[event] = handlers[event] || [];
+        events2.push([callback, namespace, priority, key]);
+        events2.sort(function (handler1, handler2) {
+          return handler1[2] - handler2[2];
         });
       });
     }
@@ -415,7 +402,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     function off(events, key) {
       forEachEvent(events, function (event, namespace) {
         handlers[event] = (handlers[event] || []).filter(function (handler) {
-          return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
+          return handler[3] ? handler[3] !== key : key || handler[1] !== namespace;
         });
       });
     }
@@ -429,7 +416,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     function emit(event) {
       var _arguments = arguments;
       (handlers[event] || []).forEach(function (handler) {
-        handler._callback.apply(handler, slice(_arguments, 1));
+        handler[0].apply(handler, slice(_arguments, 1));
       });
     }
 

File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js.map


+ 1 - 6
dist/types/index.d.ts

@@ -800,12 +800,7 @@ interface EventBusObject {
  *
  * @since 3.0.0
  */
-interface EventHandler {
-    _callback: AnyFunction;
-    _namespace: string;
-    _priority: number;
-    _key?: object;
-}
+declare type EventHandler = [AnyFunction, string, number, object?];
 /**
  * The type for a callback function of the EventBus.
  *

+ 7 - 17
src/js/constructors/EventBus/EventBus.ts

@@ -1,6 +1,6 @@
 import { DEFAULT_EVENT_PRIORITY } from '../../constants/priority';
 import { AnyFunction } from '../../types';
-import { forOwn, push, slice, toArray } from '../../utils';
+import { forOwn, slice, toArray } from '../../utils';
 
 
 /**
@@ -21,12 +21,7 @@ export interface EventBusObject {
  *
  * @since 3.0.0
  */
-export interface EventHandler {
-  _callback: AnyFunction;
-  _namespace: string;
-  _priority: number;
-  _key?: object;
-}
+export type EventHandler = [ AnyFunction, string, number, object? ];
 
 /**
  * The type for a callback function of the EventBus.
@@ -64,14 +59,9 @@ export function EventBus(): EventBusObject {
     priority = DEFAULT_EVENT_PRIORITY
   ): void {
     forEachEvent( events, ( event, namespace ) => {
-      handlers[ event ] = handlers[ event ] || [];
-
-      push( handlers[ event ], {
-        _callback : callback,
-        _namespace: namespace,
-        _priority : priority,
-        _key      : key,
-      } ).sort( ( handler1, handler2 ) => handler1._priority - handler2._priority );
+      const events = ( handlers[ event ] = handlers[ event ] || [] );
+      events.push( [ callback, namespace, priority, key ] );
+      events.sort( ( handler1, handler2 ) => handler1[ 2 ] - handler2[ 2 ] );
     } );
   }
 
@@ -86,7 +76,7 @@ export function EventBus(): EventBusObject {
   function off( events: string | string[], key?: object ): void {
     forEachEvent( events, ( event, namespace ) => {
       handlers[ event ] = ( handlers[ event ] || [] ).filter( handler => {
-        return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
+        return handler[ 3 ] ? handler[ 3 ] !== key : key || handler[ 1 ] !== namespace;
       } );
     } );
   }
@@ -111,7 +101,7 @@ export function EventBus(): EventBusObject {
   function emit( event: string ): void {
     ( handlers[ event ] || [] ).forEach( handler => {
       // eslint-disable-next-line prefer-rest-params, prefer-spread
-      handler._callback.apply( handler, slice( arguments, 1 ) );
+      handler[ 0 ].apply( handler, slice( arguments, 1 ) );
     } );
   }
 

+ 1 - 0
src/js/test/php/examples/live-regions.php

@@ -23,6 +23,7 @@ $settings = get_settings();
 	      rewind : true,
 	      perPage: 2,
 	      live   : true,
+	      speed: 1000
       } );
 
       splide.mount();

+ 1 - 3
src/js/utils/array/index.ts

@@ -2,6 +2,4 @@ export { empty }    from './empty/empty';
 export { forEach }  from './forEach/forEach';
 export { includes } from './includes/includes';
 export { push }     from './push/push';
-export { toArray }  from './toArray/toArray';
-
-export const arrayProto = Array.prototype;
+export { toArray }  from './toArray/toArray';

+ 2 - 2
src/js/utils/arrayLike/index.ts

@@ -1,2 +1,2 @@
-export { slice }  from './slice/slice';
-export { find }   from './find/find';
+export { slice } from './slice/slice';
+export { find }  from './find/find';

+ 1 - 4
src/js/utils/arrayLike/slice/slice.ts

@@ -1,6 +1,3 @@
-import { arrayProto } from '../../array';
-
-
 /**
  * The slice method for an array-like object.
  *
@@ -11,5 +8,5 @@ import { arrayProto } from '../../array';
  * @return An array with sliced elements.
  */
 export function slice<T>( arrayLike: ArrayLike<T>, start?: number, end?: number ): T[] {
-  return arrayProto.slice.call( arrayLike, start, end );
+  return Array.prototype.slice.call( arrayLike, start, end );
 }

+ 21 - 13
src/js/utils/type/type.ts

@@ -1,3 +1,19 @@
+import { AnyFunction } from '../../types';
+import { apply } from '../function';
+
+
+/**
+ * The alias of the type check function.
+ *
+ * @param type    - A type.
+ * @param subject - A subject to check.
+ *
+ * @return `true` if the subject is the specified type.
+ */
+function typeOf( type: string, subject: unknown ): boolean {
+  return typeof subject === type;
+}
+
 /**
  * Checks if the given subject is an object or not.
  *
@@ -6,7 +22,7 @@
  * @return `true` if the subject is an object, or otherwise `false`.
  */
 export function isObject( subject: unknown ): subject is object {
-  return ! isNull( subject ) && typeof subject === 'object';
+  return ! isNull( subject ) && typeOf( 'object', subject );
 }
 
 /**
@@ -16,9 +32,7 @@ export function isObject( subject: unknown ): subject is object {
  *
  * @return `true` if the subject is an array, or otherwise `false`.
  */
-export function isArray<T>( subject: unknown ): subject is T[] {
-  return Array.isArray( subject );
-}
+export const isArray: <T>( subject: unknown ) => subject is T[] = Array.isArray;
 
 /**
  * Checks if the given subject is a function or not.
@@ -27,9 +41,7 @@ export function isArray<T>( subject: unknown ): subject is T[] {
  *
  * @return `true` if the subject is a function, or otherwise `false`.
  */
-export function isFunction( subject: unknown ): subject is ( ...args: any[] ) => any {
-  return typeof subject === 'function';
-}
+export const isFunction = <( subject: unknown ) => subject is AnyFunction>apply( typeOf, 'function' );
 
 /**
  * Checks if the given subject is a string or not.
@@ -38,9 +50,7 @@ export function isFunction( subject: unknown ): subject is ( ...args: any[] ) =>
  *
  * @return `true` if the subject is a string, or otherwise `false`.
  */
-export function isString( subject: unknown ): subject is string {
-  return typeof subject === 'string';
-}
+export const isString = <( subject: unknown ) => subject is string>apply( typeOf, 'string' );
 
 /**
  * Checks if the given subject is `undefined` or not.
@@ -49,9 +59,7 @@ export function isString( subject: unknown ): subject is string {
  *
  * @return `true` if the subject is `undefined`, or otherwise `false`.
  */
-export function isUndefined( subject: unknown ): subject is undefined {
-  return typeof subject === 'undefined';
-}
+export const isUndefined = <( subject: unknown ) => subject is undefined>apply( typeOf, 'undefined' );
 
 /**
  * Checks if the given subject is `null` or not.

Some files were not shown because too many files changed in this diff