Comparing version 0.7.8-beta.3 to 0.7.8-beta.4
# Rive.js Changelog | ||
## 0.7.8-beta.4 (Apr 16, 2021) | ||
- Typescript type definitions are included in the package | ||
- Adds unsubscribe from events | ||
## 0.7.8-beta.3 (Apr 16, 2021) | ||
- Updates how webpack packages the vanilla web version to make it work nicelyt with production builds and parcel | ||
- Updates how webpack packages the vanilla web version to make it work nicely with production builds and parcel | ||
## 0.7.8-beta.2 (Apr 15, 2021) | ||
@@ -6,0 +11,0 @@ - Updates to latest wasm |
{ | ||
"name": "rive-js", | ||
"version": "0.7.8-beta.3", | ||
"version": "0.7.8-beta.4", | ||
"description": "Rive's web api.", | ||
@@ -33,2 +33,3 @@ "main": "dist/rive.dev.js", | ||
"dist/rive.wasm", | ||
"dist/rive.d.ts", | ||
"src/rive.ts" | ||
@@ -35,0 +36,0 @@ ], |
@@ -27,3 +27,3 @@ # Rive.js -- Rive's JS runtime | ||
## 0.7.8-beta.3 | ||
## 0.7.8-beta.4 | ||
@@ -34,3 +34,3 @@ This beta adds state machine support: | ||
<canvas id="canvas" width="400" height="300"></canvas> | ||
<script src="https://unpkg.com/rive-js@0.7.8-beta.3/dist/rive.min.js"></script> | ||
<script src="https://unpkg.com/rive-js@0.7.8-beta.4/dist/rive.min.js"></script> | ||
<script> | ||
@@ -226,2 +226,7 @@ new rive.Rive({ | ||
*Unsubscribing functionality is currently only in the beta release* | ||
You can unsubscribe from a single callback, all callbacks of a specific type, or every callback using: | ||
- ```unsubscribe(type, callback)``` | ||
- ```unsubscribeAll(type)```: if ```type``` is omitted, all callbacks are unsubscribed | ||
## Other Properties | ||
@@ -228,0 +233,0 @@ |
@@ -567,10 +567,37 @@ import * as rc from 'rive-canvas'; | ||
// Removes listener | ||
/** | ||
* Removes a listener | ||
* @param listener the listener with the callback to be removed | ||
*/ | ||
public remove(listener: EventListener): void { | ||
const index = this.listeners.indexOf(listener, 0); | ||
if (index > -1) { | ||
this.listeners.splice(index, 1); | ||
// We can't simply look for the listener as it'll be a different instance to | ||
// one originally subscribed. Find all the listeners of the right type and | ||
// then check their callbacks which should match. | ||
for (let i = 0; i < this.listeners.length; i++) { | ||
const currentListener = this.listeners[i]; | ||
if (currentListener.type === listener.type) { | ||
if (currentListener.callback === listener.callback) { | ||
this.listeners.splice(i, 1); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Clears all listeners of specified type, or every listener if no type is | ||
* specified | ||
* @param type the type of listeners to clear, or all listeners if not | ||
* specified | ||
*/ | ||
public removeAll(type?: EventType) { | ||
if (!type) { | ||
this.listeners.splice(0, this.listeners.length); | ||
} else { | ||
this.listeners | ||
.filter((l) => l.type === type) | ||
.forEach((l) => this.remove(l)); | ||
} | ||
} | ||
// Fires an event | ||
@@ -1196,3 +1223,7 @@ public fire(event: Event): void { | ||
// Register a new listener | ||
/** | ||
* Subscribe to Rive-generated events | ||
* @param type the type of event to subscribe to | ||
* @param callback callback to fire when the event occurs | ||
*/ | ||
public on(type: EventType, callback: EventCallback) { | ||
@@ -1206,2 +1237,23 @@ this.eventManager.add({ | ||
/** | ||
* Unsubscribes from a Rive-generated event | ||
* @param callback the callback to unsubscribe from | ||
*/ | ||
public unsubscribe(type: EventType, callback: EventCallback) { | ||
this.eventManager.remove({ | ||
type: type, | ||
callback: callback, | ||
}); | ||
} | ||
/** | ||
* Unsubscribes all listeners from an event type, or everything if no type is | ||
* given | ||
* @param type the type of event to unsubscribe from, or all types if | ||
* undefined | ||
*/ | ||
public unsubscribeAll(type?: EventType) { | ||
this.eventManager.removeAll(type); | ||
} | ||
/** | ||
* Returns the contents of a Rive file: the artboards, animations, and state machines | ||
@@ -1208,0 +1260,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1548159
10
7512
254