Skip to content

Commit

Permalink
Validate if the manager is initialized before to destroy the animations
Browse files Browse the repository at this point in the history
  • Loading branch information
jdnichollsc committed May 7, 2020
1 parent 7be7454 commit 43c7fef
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.8] - 2020-05-07
### Fixed
- Validate if the manager is initialized before to destroy the animation.
- Fixed comments of JSDoc.

## [1.1.7] - 2020-04-25
### Fixed
- Fixed `createAnimatableComponent` HOC by adding missing `animation` prop.
Expand Down
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@proyecto26/animatable-component",
"version": "1.1.7",
"version": "1.1.8",
"private": false,
"description": "Animate once, use Everywhere! 💫",
"author": "Proyecto 26",
Expand All @@ -27,14 +27,14 @@
"lint": "eslint src/**/*{.ts,.tsx}"
},
"devDependencies": {
"@stencil/core": "^1.12.5",
"@stencil/core": "^1.12.7",
"@stencil/eslint-plugin": "^0.3.1",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.19.0",
"gh-pages": "^2.2.0",
"@stencil/react-output-target": "0.0.4"
"@stencil/react-output-target": "0.0.6"
},
"license": "MIT",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@proyecto26/animatable-component-react",
"sideEffects": false,
"version": "1.0.1",
"version": "1.0.2",
"description": "React specific wrapper for animatable-component",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,7 +38,7 @@
"typescript": "^3.3.4000"
},
"dependencies": {
"@proyecto26/animatable-component": "^1.1.7"
"@proyecto26/animatable-component": "^1.1.8"
},
"peerDependencies": {
"react": "^16.7.0",
Expand Down
11 changes: 7 additions & 4 deletions react/src/react-component-lib/createComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ReactDom from 'react-dom';

import {
attachEventProps,
Expand All @@ -16,16 +15,20 @@ interface IonicReactInternalProps<ElementType> extends React.HTMLAttributes<Elem
export const createReactComponent = <PropType, ElementType>(tagName: string) => {
const displayName = dashToPascalCase(tagName);
const ReactComponent = class extends React.Component<IonicReactInternalProps<ElementType>> {

private ref: React.RefObject<HTMLElement>;

constructor(props: IonicReactInternalProps<ElementType>) {
super(props);
this.ref = React.createRef<HTMLElement>();
}

componentDidMount() {
this.componentDidUpdate(this.props);
}

componentDidUpdate(prevProps: IonicReactInternalProps<ElementType>) {
const node = ReactDom.findDOMNode(this) as HTMLElement;
const node = this.ref.current;
attachEventProps(node, this.props, prevProps);
}

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

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

const newProps: any = {
...propsToPass,
ref: forwardedRef,
ref: this.ref,
style,
className,
};
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const easingOutCubic = EASING_FUNCTIONS[EASING.EASE_OUT_CUBIC];

### Script tag

- 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
- 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
- Then you can use the element anywhere in your template, JSX, html etc

### Node Modules
Expand Down
6 changes: 4 additions & 2 deletions src/components/animatable-component/animatable-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AnimatableComponent implements IAnimatableComponent {
/**
* Animation manager for Animatable
*/
private manager: AnimationManager
private manager?: AnimationManager = null

@Element() el!: HTMLElement

Expand Down Expand Up @@ -315,7 +315,9 @@ export class AnimatableComponent implements IAnimatableComponent {
*/
@Method()
async destroy(): Promise<void> {
this.manager.destroyAnimation();
if (this.manager !== null) {
this.manager.destroyAnimation();
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/components/animatable-cube/animatable-cube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Cube implements IAnimatableComponent {
/**
* Animation manager for Animatable
*/
private manager: AnimationManager
private manager?: AnimationManager = null

@Element() el!: HTMLElement

Expand Down Expand Up @@ -325,7 +325,9 @@ export class Cube implements IAnimatableComponent {
*/
@Method()
async destroy(): Promise<void> {
this.manager.destroyAnimation();
if (this.manager !== null) {
this.manager.destroyAnimation();
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/utils/waapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { IAnimatable } from '../models/animatable';

/**
* Create a new animation.
* @param param0 - The data of the new animation.
* @param element - The element to animate.
* @param context - Animatable context.
*/
function createAnimation (
element: HTMLElement,
Expand Down Expand Up @@ -47,7 +48,7 @@ export function clearPropsWithOptions (

/**
* Load the options of the animation.
* @param param0 - The data of the new animation.
* @param context - The data of the animation.
*/
export function getAnimationOptions (
context: IAnimatable
Expand Down Expand Up @@ -81,6 +82,9 @@ export function getAnimationOptions (
return animationOptions;
}

/**
* A manager to handle the animations of the Components.
*/
export class AnimationManager {
private element: HTMLElement
private state: IAnimatable
Expand Down

0 comments on commit 43c7fef

Please sign in to comment.