Skip to content

Commit 43c7fef

Browse files
committed
Validate if the manager is initialized before to destroy the animations
1 parent 7be7454 commit 43c7fef

File tree

10 files changed

+60
-44
lines changed

10 files changed

+60
-44
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.1.8] - 2020-05-07
10+
### Fixed
11+
- Validate if the manager is initialized before to destroy the animation.
12+
- Fixed comments of JSDoc.
13+
914
## [1.1.7] - 2020-04-25
1015
### Fixed
1116
- Fixed `createAnimatableComponent` HOC by adding missing `animation` prop.

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@proyecto26/animatable-component",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"private": false,
55
"description": "Animate once, use Everywhere! 💫",
66
"author": "Proyecto 26",
@@ -27,14 +27,14 @@
2727
"lint": "eslint src/**/*{.ts,.tsx}"
2828
},
2929
"devDependencies": {
30-
"@stencil/core": "^1.12.5",
30+
"@stencil/core": "^1.12.7",
3131
"@stencil/eslint-plugin": "^0.3.1",
32-
"@typescript-eslint/eslint-plugin": "^2.28.0",
33-
"@typescript-eslint/parser": "^2.28.0",
32+
"@typescript-eslint/eslint-plugin": "^2.31.0",
33+
"@typescript-eslint/parser": "^2.31.0",
3434
"eslint": "^6.8.0",
3535
"eslint-plugin-react": "^7.19.0",
3636
"gh-pages": "^2.2.0",
37-
"@stencil/react-output-target": "0.0.4"
37+
"@stencil/react-output-target": "0.0.6"
3838
},
3939
"license": "MIT",
4040
"repository": {

react/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@proyecto26/animatable-component-react",
33
"sideEffects": false,
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"description": "React specific wrapper for animatable-component",
66
"repository": {
77
"type": "git",
@@ -38,7 +38,7 @@
3838
"typescript": "^3.3.4000"
3939
},
4040
"dependencies": {
41-
"@proyecto26/animatable-component": "^1.1.7"
41+
"@proyecto26/animatable-component": "^1.1.8"
4242
},
4343
"peerDependencies": {
4444
"react": "^16.7.0",

react/src/react-component-lib/createComponent.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import ReactDom from 'react-dom';
32

43
import {
54
attachEventProps,
@@ -16,16 +15,20 @@ interface IonicReactInternalProps<ElementType> extends React.HTMLAttributes<Elem
1615
export const createReactComponent = <PropType, ElementType>(tagName: string) => {
1716
const displayName = dashToPascalCase(tagName);
1817
const ReactComponent = class extends React.Component<IonicReactInternalProps<ElementType>> {
18+
19+
private ref: React.RefObject<HTMLElement>;
20+
1921
constructor(props: IonicReactInternalProps<ElementType>) {
2022
super(props);
23+
this.ref = React.createRef<HTMLElement>();
2124
}
2225

2326
componentDidMount() {
2427
this.componentDidUpdate(this.props);
2528
}
2629

2730
componentDidUpdate(prevProps: IonicReactInternalProps<ElementType>) {
28-
const node = ReactDom.findDOMNode(this) as HTMLElement;
31+
const node = this.ref.current;
2932
attachEventProps(node, this.props, prevProps);
3033
}
3134

@@ -39,7 +42,7 @@ export const createReactComponent = <PropType, ElementType>(tagName: string) =>
3942

4043
if (isEventProp) {
4144
const eventName = name.substring(2).toLowerCase();
42-
if (isCoveredByReact(eventName)) {
45+
if (typeof document !== "undefined" && isCoveredByReact(eventName)) {
4346
(acc as any)[name] = (cProps as any)[name];
4447
}
4548
} else if (isDataProp || isAriaProp) {
@@ -50,7 +53,7 @@ export const createReactComponent = <PropType, ElementType>(tagName: string) =>
5053

5154
const newProps: any = {
5255
...propsToPass,
53-
ref: forwardedRef,
56+
ref: this.ref,
5457
style,
5558
className,
5659
};

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const easingOutCubic = EASING_FUNCTIONS[EASING.EASE_OUT_CUBIC];
104104

105105
### Script tag
106106

107-
- Put a script tag similar to this `<script src='https://unpkg.com/animatable-component@1.1.7/dist/animatable-component.js'></script>` in the head of your index.html
107+
- Put a script tag similar to this `<script src='https://unpkg.com/animatable-component@1.1.8/dist/animatable-component.js'></script>` in the head of your index.html
108108
- Then you can use the element anywhere in your template, JSX, html etc
109109

110110
### Node Modules

src/components/animatable-component/animatable-component.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class AnimatableComponent implements IAnimatableComponent {
3434
/**
3535
* Animation manager for Animatable
3636
*/
37-
private manager: AnimationManager
37+
private manager?: AnimationManager = null
3838

3939
@Element() el!: HTMLElement
4040

@@ -315,7 +315,9 @@ export class AnimatableComponent implements IAnimatableComponent {
315315
*/
316316
@Method()
317317
async destroy(): Promise<void> {
318-
this.manager.destroyAnimation();
318+
if (this.manager !== null) {
319+
this.manager.destroyAnimation();
320+
}
319321
}
320322

321323
/**

src/components/animatable-cube/animatable-cube.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Cube implements IAnimatableComponent {
4444
/**
4545
* Animation manager for Animatable
4646
*/
47-
private manager: AnimationManager
47+
private manager?: AnimationManager = null
4848

4949
@Element() el!: HTMLElement
5050

@@ -325,7 +325,9 @@ export class Cube implements IAnimatableComponent {
325325
*/
326326
@Method()
327327
async destroy(): Promise<void> {
328-
this.manager.destroyAnimation();
328+
if (this.manager !== null) {
329+
this.manager.destroyAnimation();
330+
}
329331
}
330332

331333
/**

src/utils/waapi.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { IAnimatable } from '../models/animatable';
44

55
/**
66
* Create a new animation.
7-
* @param param0 - The data of the new animation.
7+
* @param element - The element to animate.
8+
* @param context - Animatable context.
89
*/
910
function createAnimation (
1011
element: HTMLElement,
@@ -47,7 +48,7 @@ export function clearPropsWithOptions (
4748

4849
/**
4950
* Load the options of the animation.
50-
* @param param0 - The data of the new animation.
51+
* @param context - The data of the animation.
5152
*/
5253
export function getAnimationOptions (
5354
context: IAnimatable
@@ -81,6 +82,9 @@ export function getAnimationOptions (
8182
return animationOptions;
8283
}
8384

85+
/**
86+
* A manager to handle the animations of the Components.
87+
*/
8488
export class AnimationManager {
8589
private element: HTMLElement
8690
private state: IAnimatable

0 commit comments

Comments
 (0)