Skip to content

Commit 10a34c3

Browse files
authored
fix: handle undefined trigger (#13)
* fix: handle when no valid trigger is returned * fix: use this._onceOnly
1 parent a29facd commit 10a34c3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/frontend/scripts/class-timeline.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ export class Timeline {
2525
this._onceOnly = !! timelineData.onceOnly
2626
this._actionStarts = {}
2727

28-
// Used to track if the timeline is played per each trigger.
29-
this.timelineData._playedTriggers = new WeakSet()
28+
// Only track played triggers if onceOnly is enabled.
29+
if ( this._onceOnly && ! this.timelineData._playedTriggers ) {
30+
this.timelineData._playedTriggers = new Set()
31+
}
3032
}
3133

3234
this._targets = []
@@ -44,14 +46,13 @@ export class Timeline {
4446
createInstance( options ) {
4547
// If triggered only once, then we don't create anymore animations.
4648
const currentTrigger = this.interaction.getCurrentTrigger()
47-
if ( this.getRunner().isFrontend ) {
48-
if ( this.timelineData.onceOnly && this.timelineData._playedTriggers.has( currentTrigger ) ) {
49+
if ( this.getRunner().isFrontend && currentTrigger && this._onceOnly ) {
50+
if ( this.timelineData._playedTriggers.has( currentTrigger ) ) {
4951
return null
5052
}
53+
this.timelineData._playedTriggers.add( currentTrigger )
5154
}
5255

53-
this.timelineData._playedTriggers.add( currentTrigger )
54-
5556
// We have to empty the promises here because we are creating a new timeline.
5657
// This is to prevent the promises from the previous timeline from affecting the new one.
5758
this._funcPromises = {}

0 commit comments

Comments
 (0)