Skip to content

Commit 514a2cc

Browse files
Refactoring with Media#set(). Add transformIgnorePatterns to fix the issue that jest fails to rename caches.
1 parent 3449e06 commit 514a2cc

File tree

10 files changed

+74
-58
lines changed

10 files changed

+74
-58
lines changed

dist/js/splide.cjs.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,7 @@ function Media(Splide2, Components2, options) {
610610
return merge(merged2, entry[1].matches ? entry[0] : {});
611611
}, {});
612612
omit(options);
613-
merge(options, merged);
614-
615-
if (!state.is(CREATED)) {
616-
Splide2.emit(EVENT_UPDATED, options);
617-
}
613+
set(merged);
618614

619615
if (options.destroy) {
620616
Splide2.destroy(options.destroy === "completely");
@@ -632,10 +628,20 @@ function Media(Splide2, Components2, options) {
632628
}
633629
}
634630

631+
function set(opts, user) {
632+
merge(options, opts);
633+
user && merge(Object.getPrototypeOf(options), opts);
634+
635+
if (!state.is(CREATED)) {
636+
Splide2.emit(EVENT_UPDATED, options);
637+
}
638+
}
639+
635640
return {
636641
setup: setup,
637642
destroy: destroy,
638-
reduce: reduce
643+
reduce: reduce,
644+
set: set
639645
};
640646
}
641647

@@ -3087,13 +3093,7 @@ var _Splide = /*#__PURE__*/function () {
30873093
return this._o;
30883094
},
30893095
set: function set(options) {
3090-
var _o = this._o;
3091-
merge(_o, options);
3092-
merge(Object.getPrototypeOf(_o), options);
3093-
3094-
if (!this.state.is(CREATED)) {
3095-
this.emit(EVENT_UPDATED, _o);
3096-
}
3096+
this._C.Media.set(options, true);
30973097
}
30983098
}, {
30993099
key: "length",

dist/js/splide.esm.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,7 @@ function Media(Splide2, Components2, options) {
605605
return merge(merged2, entry[1].matches ? entry[0] : {});
606606
}, {});
607607
omit(options);
608-
merge(options, merged);
609-
610-
if (!state.is(CREATED)) {
611-
Splide2.emit(EVENT_UPDATED, options);
612-
}
608+
set(merged);
613609

614610
if (options.destroy) {
615611
Splide2.destroy(options.destroy === "completely");
@@ -627,10 +623,20 @@ function Media(Splide2, Components2, options) {
627623
}
628624
}
629625

626+
function set(opts, user) {
627+
merge(options, opts);
628+
user && merge(Object.getPrototypeOf(options), opts);
629+
630+
if (!state.is(CREATED)) {
631+
Splide2.emit(EVENT_UPDATED, options);
632+
}
633+
}
634+
630635
return {
631636
setup: setup,
632637
destroy: destroy,
633-
reduce: reduce
638+
reduce: reduce,
639+
set: set
634640
};
635641
}
636642

@@ -3082,13 +3088,7 @@ var _Splide = /*#__PURE__*/function () {
30823088
return this._o;
30833089
},
30843090
set: function set(options) {
3085-
var _o = this._o;
3086-
merge(_o, options);
3087-
merge(Object.getPrototypeOf(_o), options);
3088-
3089-
if (!this.state.is(CREATED)) {
3090-
this.emit(EVENT_UPDATED, _o);
3091-
}
3091+
this._C.Media.set(options, true);
30923092
}
30933093
}, {
30943094
key: "length",

dist/js/splide.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
606606
return merge(merged2, entry[1].matches ? entry[0] : {});
607607
}, {});
608608
omit(options);
609-
merge(options, merged);
610-
611-
if (!state.is(CREATED)) {
612-
Splide2.emit(EVENT_UPDATED, options);
613-
}
609+
set(merged);
614610

615611
if (options.destroy) {
616612
Splide2.destroy(options.destroy === "completely");
@@ -628,10 +624,20 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
628624
}
629625
}
630626

627+
function set(opts, user) {
628+
merge(options, opts);
629+
user && merge(Object.getPrototypeOf(options), opts);
630+
631+
if (!state.is(CREATED)) {
632+
Splide2.emit(EVENT_UPDATED, options);
633+
}
634+
}
635+
631636
return {
632637
setup: setup,
633638
destroy: destroy,
634-
reduce: reduce
639+
reduce: reduce,
640+
set: set
635641
};
636642
}
637643

@@ -3080,13 +3086,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
30803086
return this._o;
30813087
},
30823088
set: function set(options) {
3083-
var _o = this._o;
3084-
merge(_o, options);
3085-
merge(Object.getPrototypeOf(_o), options);
3086-
3087-
if (!this.state.is(CREATED)) {
3088-
this.emit(EVENT_UPDATED, _o);
3089-
}
3089+
this._C.Media.set(options, true);
30903090
}
30913091
}, {
30923092
key: "length",

dist/js/splide.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/splide.min.js.gz

11 Bytes
Binary file not shown.

dist/js/splide.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
interface MediaComponent extends BaseComponent {
77
/** @internal */
88
reduce(reduced: boolean): void;
9+
set(options: Options, userOptions?: boolean): void;
910
}
1011

1112
/**

jest.config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
module.exports = {
2-
rootDir : './src',
2+
rootDir: './src',
33
transform: {
44
'^.+\\.(ts|tsx)$': 'ts-jest',
55
},
66
testEnvironment: 'jsdom',
7-
setupFiles: [
8-
'./js/test/jest/setup.ts',
9-
],
7+
setupFiles: [
8+
'./js/test/jest/setup.ts',
9+
],
10+
transformIgnorePatterns: [
11+
'<rootDir>/node_modules/@babel',
12+
'<rootDir>/node_modules/@jest',
13+
],
1014
};

src/js/components/Media/Media.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { EVENT_UPDATED } from "../../constants/events";
1515
export interface MediaComponent extends BaseComponent {
1616
/** @internal */
1717
reduce( reduced: boolean ): void;
18+
set( options: Options, userOptions?: boolean ): void;
1819
}
1920

2021
/**
@@ -90,11 +91,7 @@ export function Media( Splide: Splide, Components: Components, options: Options
9091
}, {} );
9192

9293
omit( options );
93-
merge( options, merged );
94-
95-
if ( ! state.is( CREATED ) ) {
96-
Splide.emit( EVENT_UPDATED, options );
97-
}
94+
set( merged );
9895

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

120+
/**
121+
* Sets options.
122+
*
123+
* @internal
124+
*
125+
* @param opts - New options.
126+
* @param user - Optional. Determines whether to also update user options or not.
127+
*/
128+
function set( opts: Options, user?: boolean ): void {
129+
merge( options, opts );
130+
user && merge( Object.getPrototypeOf( options ), opts );
131+
132+
if ( ! state.is( CREATED ) ) {
133+
Splide.emit( EVENT_UPDATED, options );
134+
}
135+
}
136+
121137
return {
122138
setup,
123139
destroy,
124140
reduce,
141+
set,
125142
};
126143
}

src/js/core/Splide/Splide.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as ComponentConstructors from '../../components';
22
import { SlideMatcher } from '../../components/Slides/Slides';
33
import { CLASS_INITIALIZED } from '../../constants/classes';
44
import { DEFAULTS } from '../../constants/defaults';
5-
import { EVENT_DESTROY, EVENT_MOUNTED, EVENT_READY, EVENT_REFRESH, EVENT_UPDATED } from '../../constants/events';
5+
import { EVENT_DESTROY, EVENT_MOUNTED, EVENT_READY, EVENT_REFRESH } from '../../constants/events';
66
import { DATA_ATTRIBUTE } from '../../constants/project';
77
import { CREATED, DESTROYED, IDLE, STATES } from '../../constants/states';
88
import { FADE } from '../../constants/types';
@@ -379,13 +379,7 @@ export class Splide {
379379
* @param options - An object with new options.
380380
*/
381381
set options( options: Options ) {
382-
const { _o } = this;
383-
merge( _o, options );
384-
merge( Object.getPrototypeOf( _o ), options );
385-
386-
if ( ! this.state.is( CREATED ) ) {
387-
this.emit( EVENT_UPDATED, _o );
388-
}
382+
this._C.Media.set( options, true );
389383
}
390384

391385
/**

0 commit comments

Comments
 (0)