Skip to content

Commit

Permalink
Refactoring with Media#set(). Add transformIgnorePatterns to fix …
Browse files Browse the repository at this point in the history
…the issue that jest fails to rename caches.
  • Loading branch information
NaotoshiFujita committed Apr 6, 2022
1 parent 3449e06 commit 514a2cc
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 58 deletions.
26 changes: 13 additions & 13 deletions dist/js/splide.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,7 @@ function Media(Splide2, Components2, options) {
return merge(merged2, entry[1].matches ? entry[0] : {});
}, {});
omit(options);
merge(options, merged);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
set(merged);

if (options.destroy) {
Splide2.destroy(options.destroy === "completely");
Expand All @@ -632,10 +628,20 @@ function Media(Splide2, Components2, options) {
}
}

function set(opts, user) {
merge(options, opts);
user && merge(Object.getPrototypeOf(options), opts);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
}

return {
setup: setup,
destroy: destroy,
reduce: reduce
reduce: reduce,
set: set
};
}

Expand Down Expand Up @@ -3087,13 +3093,7 @@ var _Splide = /*#__PURE__*/function () {
return this._o;
},
set: function set(options) {
var _o = this._o;
merge(_o, options);
merge(Object.getPrototypeOf(_o), options);

if (!this.state.is(CREATED)) {
this.emit(EVENT_UPDATED, _o);
}
this._C.Media.set(options, true);
}
}, {
key: "length",
Expand Down
26 changes: 13 additions & 13 deletions dist/js/splide.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,7 @@ function Media(Splide2, Components2, options) {
return merge(merged2, entry[1].matches ? entry[0] : {});
}, {});
omit(options);
merge(options, merged);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
set(merged);

if (options.destroy) {
Splide2.destroy(options.destroy === "completely");
Expand All @@ -627,10 +623,20 @@ function Media(Splide2, Components2, options) {
}
}

function set(opts, user) {
merge(options, opts);
user && merge(Object.getPrototypeOf(options), opts);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
}

return {
setup: setup,
destroy: destroy,
reduce: reduce
reduce: reduce,
set: set
};
}

Expand Down Expand Up @@ -3082,13 +3088,7 @@ var _Splide = /*#__PURE__*/function () {
return this._o;
},
set: function set(options) {
var _o = this._o;
merge(_o, options);
merge(Object.getPrototypeOf(_o), options);

if (!this.state.is(CREATED)) {
this.emit(EVENT_UPDATED, _o);
}
this._C.Media.set(options, true);
}
}, {
key: "length",
Expand Down
26 changes: 13 additions & 13 deletions dist/js/splide.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
return merge(merged2, entry[1].matches ? entry[0] : {});
}, {});
omit(options);
merge(options, merged);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
set(merged);

if (options.destroy) {
Splide2.destroy(options.destroy === "completely");
Expand All @@ -628,10 +624,20 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
}
}

function set(opts, user) {
merge(options, opts);
user && merge(Object.getPrototypeOf(options), opts);

if (!state.is(CREATED)) {
Splide2.emit(EVENT_UPDATED, options);
}
}

return {
setup: setup,
destroy: destroy,
reduce: reduce
reduce: reduce,
set: set
};
}

Expand Down Expand Up @@ -3080,13 +3086,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
return this._o;
},
set: function set(options) {
var _o = this._o;
merge(_o, options);
merge(Object.getPrototypeOf(_o), options);

if (!this.state.is(CREATED)) {
this.emit(EVENT_UPDATED, _o);
}
this._C.Media.set(options, true);
}
}, {
key: "length",
Expand Down
2 changes: 1 addition & 1 deletion dist/js/splide.min.js

Large diffs are not rendered by default.

Binary file modified dist/js/splide.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/js/splide.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
interface MediaComponent extends BaseComponent {
/** @internal */
reduce(reduced: boolean): void;
set(options: Options, userOptions?: boolean): void;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module.exports = {
rootDir : './src',
rootDir: './src',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testEnvironment: 'jsdom',
setupFiles: [
'./js/test/jest/setup.ts',
],
setupFiles: [
'./js/test/jest/setup.ts',
],
transformIgnorePatterns: [
'<rootDir>/node_modules/@babel',
'<rootDir>/node_modules/@jest',
],
};
27 changes: 22 additions & 5 deletions src/js/components/Media/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EVENT_UPDATED } from "../../constants/events";
export interface MediaComponent extends BaseComponent {
/** @internal */
reduce( reduced: boolean ): void;
set( options: Options, userOptions?: boolean ): void;
}

/**
Expand Down Expand Up @@ -90,11 +91,7 @@ export function Media( Splide: Splide, Components: Components, options: Options
}, {} );

omit( options );
merge( options, merged );

if ( ! state.is( CREATED ) ) {
Splide.emit( EVENT_UPDATED, options );
}
set( merged );

if ( options.destroy ) {
Splide.destroy( options.destroy === 'completely' );
Expand All @@ -110,6 +107,8 @@ export function Media( Splide: Splide, Components: Components, options: Options
* Disables or enables `reducedMotion` options.
* This method does nothing when the document does not match the query.
*
* @internal
*
* @param enable - Determines whether to apply `reducedMotion` options or not.
*/
function reduce( enable: boolean ): void {
Expand All @@ -118,9 +117,27 @@ export function Media( Splide: Splide, Components: Components, options: Options
}
}

/**
* Sets options.
*
* @internal
*
* @param opts - New options.
* @param user - Optional. Determines whether to also update user options or not.
*/
function set( opts: Options, user?: boolean ): void {
merge( options, opts );
user && merge( Object.getPrototypeOf( options ), opts );

if ( ! state.is( CREATED ) ) {
Splide.emit( EVENT_UPDATED, options );
}
}

return {
setup,
destroy,
reduce,
set,
};
}
10 changes: 2 additions & 8 deletions src/js/core/Splide/Splide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ComponentConstructors from '../../components';
import { SlideMatcher } from '../../components/Slides/Slides';
import { CLASS_INITIALIZED } from '../../constants/classes';
import { DEFAULTS } from '../../constants/defaults';
import { EVENT_DESTROY, EVENT_MOUNTED, EVENT_READY, EVENT_REFRESH, EVENT_UPDATED } from '../../constants/events';
import { EVENT_DESTROY, EVENT_MOUNTED, EVENT_READY, EVENT_REFRESH } from '../../constants/events';
import { DATA_ATTRIBUTE } from '../../constants/project';
import { CREATED, DESTROYED, IDLE, STATES } from '../../constants/states';
import { FADE } from '../../constants/types';
Expand Down Expand Up @@ -379,13 +379,7 @@ export class Splide {
* @param options - An object with new options.
*/
set options( options: Options ) {
const { _o } = this;
merge( _o, options );
merge( Object.getPrototypeOf( _o ), options );

if ( ! this.state.is( CREATED ) ) {
this.emit( EVENT_UPDATED, _o );
}
this._C.Media.set( options, true );
}

/**
Expand Down

0 comments on commit 514a2cc

Please sign in to comment.