Skip to content

Commit f509499

Browse files
committed
fix casting of getTimeline/getComponent to IMubanTransitionMixin instead of the parentController.
1 parent 48362da commit f509499

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

example/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ <h1 class="site-header-title">Muban <span>Transition Component</span></h1>
2626
<div class="abs-center js-text-content">
2727
<h1 class="heading-01">Scroll Transition</h1>
2828
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
29+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
2930
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
3031
<div class="looping-animation js-loop-animation"></div>
3132
</div>
@@ -47,6 +48,7 @@ <h2 class="heading-02 abs-center js-title">Regular Transition</h2>
4748
<div class="abs-center js-text-content">
4849
<h1 class="heading-01">Scroll Transition</h1>
4950
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
51+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
5052

5153
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
5254
<div class="looping-animation js-loop-animation"></div>
@@ -70,6 +72,7 @@ <h2 class="heading-02 abs-center js-title">Regular Transition</h2>
7072
<div class="abs-center js-text-content">
7173
<h1 class="heading-01">Scroll Transition</h1>
7274
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
75+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
7376

7477
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
7578
<div class="looping-animation js-loop-animation"></div>
@@ -93,6 +96,7 @@ <h2 class="heading-02 abs-center js-title">Regular Transition</h2>
9396
<div class="abs-center js-text-content">
9497
<h1 class="heading-01">Scroll Transition</h1>
9598
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
99+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
96100

97101
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
98102
<div class="looping-animation js-loop-animation"></div>
@@ -116,6 +120,7 @@ <h2 class="heading-02 abs-center js-title">Regular Transition</h2>
116120
<div class="abs-center js-text-content">
117121
<h1 class="heading-01">Scroll Transition</h1>
118122
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
123+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
119124

120125
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
121126
<div class="looping-animation js-loop-animation"></div>
@@ -139,6 +144,7 @@ <h2 class="heading-02 abs-center js-title">Regular Transition</h2>
139144
<div class="abs-center js-text-content">
140145
<h1 class="heading-01">Scroll Transition</h1>
141146
<button data-component="primary-button" class="primary-button button js-button-open">Open popup</button>
147+
<button data-component="primary-button" class="primary-button button js-button-open-2">Open popup 2</button>
142148

143149
<h2 class="looping-animation-title heading-03 js-looping-title">Looping Animation</h2>
144150
<div class="looping-animation js-loop-animation"></div>

example/src/component/DummyFooPopup/DummyFooPopupTransitionController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import MubanTransitionController from '../../../../src/lib/util/MubanTransitionC
22
import { Expo, Back, TimelineMax } from 'gsap';
33
import DummyFooPopup from './DummyFooPopup';
44

5-
class DummyFooPopupTransitionController extends MubanTransitionController<DummyFooPopup> {
5+
class DummyFooPopupTransitionController extends MubanTransitionController {
66
/**
77
* @public
88
* @method setupTransitionInTimeline

example/src/component/block/DummyFoo/DummyFooTransitionController.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import MubanTransitionController from '../../../../../src/lib/util/MubanTransiti
22
import { Expo, TimelineMax } from 'gsap';
33
import TransitionDirection from 'transition-controller/lib/enum/TransitionDirection';
44
import DummyFoo from './DummyFoo';
5+
import getComponentForElement from 'muban-core/lib/utils/getComponentForElement';
6+
import PrimaryButton from '../../button/PrimaryButton/PrimaryButton';
57

6-
class DummyFooTransitionController extends MubanTransitionController<DummyFoo> {
8+
class DummyFooTransitionController extends MubanTransitionController {
79

810
/**
911
* Use this method to setup your transition in timeline
@@ -21,7 +23,6 @@ class DummyFooTransitionController extends MubanTransitionController<DummyFoo> {
2123
parent.test();
2224

2325
const textContent:HTMLElement = parent.getElement('.js-text-content');
24-
const primaryButton:HTMLElement = parent.getElement('.js-button-open');
2526
const loopingTitle:HTMLElement = parent.getElement('.js-looping-title');
2627
const loopingAnimation:HTMLElement = parent.getElement('.js-loop-animation');
2728

@@ -31,7 +32,10 @@ class DummyFooTransitionController extends MubanTransitionController<DummyFoo> {
3132
timeline.from(textContent, 0.8, {opacity: 0}, 'afterBg');
3233
timeline.from(textContent, 0.8, {y: 30, ease: Expo.easeOut, clearProps: 'all'}, 'afterBg');
3334

34-
timeline.add(this.getTimeline(primaryButton, TransitionDirection.IN), 'afterBg+=0.2');
35+
const component = <PrimaryButton>getComponentForElement(parent.getElement('.js-button-open'));
36+
37+
timeline.add(this.getTimeline(component, TransitionDirection.IN), 'afterBg+=0.2');
38+
timeline.add(this.getTimeline(<HTMLElement>parent.getElement('.js-button-open-2'), TransitionDirection.IN), 'afterBg+=0.2');
3539

3640
timeline.from(loopingTitle, 0.8, {opacity: 0}, 'afterBg+=0.4');
3741
timeline.from(loopingTitle, 0.8, {y: 20, ease: Expo.easeOut}, 'afterBg+=0.4');

example/src/component/button/PrimaryButton/PrimaryButtonTransitionController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import MubanTransitionController from '../../../../../src/lib/util/MubanTransiti
22
import { Expo, TimelineMax } from 'gsap';
33
import PrimaryButton from './PrimaryButton';
44

5-
class PrimaryButtonTransitionController extends MubanTransitionController<PrimaryButton> {
5+
class PrimaryButtonTransitionController extends MubanTransitionController {
66
/**
77
* Use this method to setup your transition in timeline
88
*

src/lib/util/MubanTransitionController.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ import isElement from 'lodash/isElement';
44
import isString from 'lodash/isString';
55
import { IMubanTransitionMixin } from '../interface/IMubanTransitionMixin';
66

7-
export default abstract class MubanTransitionController<
8-
T extends IMubanTransitionMixin
9-
> extends AbstractTransitionController<T> {
7+
export default abstract class MubanTransitionController extends AbstractTransitionController<
8+
IMubanTransitionMixin
9+
> {
1010
/**
1111
* This method finds a component based on a string, a html element or the instance.
1212
*
1313
* @protected
1414
* @param {string | HTMLElement | IMubanTransitionMixin} component
1515
* @returns {IMubanTransitionMixin}
1616
*/
17-
protected getComponent(component: string | HTMLElement | T): T {
18-
let instance: T;
17+
protected getComponent(
18+
component: string | HTMLElement | IMubanTransitionMixin,
19+
): IMubanTransitionMixin {
20+
let instance: IMubanTransitionMixin;
1921

2022
if (isElement(component)) {
21-
instance = getComponentForElement<T>(<HTMLElement>component);
23+
instance = getComponentForElement<IMubanTransitionMixin>(<HTMLElement>component);
2224
} else if (isString(component)) {
23-
instance = getComponentForElement<T>(this.parentController.getElement(<string>component));
25+
instance = getComponentForElement<IMubanTransitionMixin>(
26+
this.parentController.getElement(<string>component),
27+
);
2428
} else {
25-
instance = <T>component;
29+
instance = <IMubanTransitionMixin>component;
2630
}
2731

2832
if (instance === undefined) {

tool/convert.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const actions = [
66
{
77
type: actionType.RUN,
88
label: 'Update the seng-generator template path.',
9-
command: 'sg settings -t ./build-tools/template,./node_modules/muban-transition-component/template',
9+
command: 'sg settings -t ./build-tools/generator-template,./node_modules/muban-transition-component/template',
1010
},
1111
{
1212
type: actionType.REPLACE,
@@ -16,7 +16,6 @@ const actions = [
1616
}
1717
];
1818

19-
2019
confirm('Running this script will replace/adapt files, are you running this on a clean project?', function (ok) {
2120
if (ok) {
2221
sequentialPromises(parseActions(actions))

0 commit comments

Comments
 (0)