Skip to content

Commit

Permalink
add destroyScene on unbind event
Browse files Browse the repository at this point in the history
  • Loading branch information
aaburkov committed Dec 6, 2021
1 parent 99c1eb1 commit 01064c3
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dist/main.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions dist/types/v-snow/Directive.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
import { DirectiveBinding } from "vue/types/options";
declare const _default: {
inserted(el: HTMLElement, binding: DirectiveBinding): void;
update(el: HTMLElement, binding: DirectiveBinding): void;
};
declare const _default: import("vue/types/options").DirectiveOptions;
export default _default;
2 changes: 1 addition & 1 deletion dist/types/v-snow/Scene.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class Scene {
private checkConfig;
private calcDensityByWidth;
private buildScene;
private destroyScene;
destroyScene(): void;
private generateFlakes;
private loadImage;
private checkImages;
Expand Down
4 changes: 2 additions & 2 deletions dist/v-snow.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/v-snow.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"description": "Snowfall effect for Vue js",
"main": "dist/v-snow.min.js",
"files": [
"dist/v-snow.js",
"dist/v-snow.min.js",
"dist/types/v-snow"
],
"typings": "dist/types/v-snow/index.d.ts",
"version": "1.0.6",
"version": "1.0.8",
"author": "Alexander Burkov <[email protected]>",
"keywords": [
"snow",
Expand Down
5 changes: 4 additions & 1 deletion src/v-snow/Component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default Vue.extend({
opacity: Number,
images: Array as PropType<string[]>,
zIndex: String,
show: Boolean
show: {
type: Boolean,
default: true
}
},
data(): State {
return {
Expand Down
12 changes: 8 additions & 4 deletions src/v-snow/Directive.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { DirectiveBinding } from "vue/types/options";
import { DirectiveOptions } from "vue/types/umd";
import Scene from "./Scene";

const statefulDirective = () => {
let scene: Scene;
const statefulDirective = (): DirectiveOptions => {
let scene: Scene | null;
return {
inserted(el: HTMLElement, binding: DirectiveBinding) {
scene = new Scene(el, binding.value);
scene.start();
},
update(el: HTMLElement, binding: DirectiveBinding) {
scene.updateConfig(binding.value);
scene.start();
scene?.updateConfig(binding.value);
scene?.start();
},
unbind() {
scene?.destroyScene();
}
};
};
Expand Down
6 changes: 5 additions & 1 deletion src/v-snow/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class Scene {
this.buildScene();
this.start();
}

private checkConfig(config: SceneConfig) {
if (config.density > 100 || config.density < 1) {
throw new Error(
Expand Down Expand Up @@ -94,8 +95,11 @@ export default class Scene {
this.initialised = true;
}

private destroyScene(): void {
public destroyScene(): void {
this.canvas?.remove();
this.RO.disconnect();
this.flakes = [];
this.isRun = false;
this.initialised = false;
}

Expand Down

0 comments on commit 01064c3

Please sign in to comment.