Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of Tween#setCallback() and Timeline#setCallback() #5757

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tweens/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ var Timeline = new Class({
{
if (Timeline.TYPES.indexOf(type) !== -1)
{
this.callbacks[type] = { func: callback, scope: scope, params: params };
this.callbacks[type] = { func: callback, scope: scope, params: [ this ].concat(params) };
}

return this;
Expand Down
6 changes: 1 addition & 5 deletions src/tweens/builders/NumberTweenBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ var NumberTweenBuilder = function (parent, config, defaults)
// Set the Callbacks
var scope = GetValue(config, 'callbackScope', tween);

// Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params
var tweenArray = [ tween, null ];

var callbacks = Tween.TYPES;

for (var i = 0; i < callbacks.length; i++)
Expand All @@ -113,8 +110,7 @@ var NumberTweenBuilder = function (parent, config, defaults)
var callbackScope = GetValue(config, type + 'Scope', scope);
var callbackParams = GetValue(config, type + 'Params', []);

// The null is reset to be the Tween target
tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope);
tween.setCallback(type, callback, callbackParams, callbackScope);
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/tweens/builders/TimelineBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ var TimelineBuilder = function (manager, config)
// Callbacks

var scope = GetValue(config, 'callbackScope', timeline);

var timelineArray = [ timeline ];

var onStart = GetValue(config, 'onStart', false);

// The Start of the Timeline
Expand All @@ -51,7 +48,7 @@ var TimelineBuilder = function (manager, config)
var onStartScope = GetValue(config, 'onStartScope', scope);
var onStartParams = GetValue(config, 'onStartParams', []);

timeline.setCallback('onStart', onStart, timelineArray.concat(onStartParams), onStartScope);
timeline.setCallback('onStart', onStart, onStartParams, onStartScope);
}

var onUpdate = GetValue(config, 'onUpdate', false);
Expand All @@ -62,7 +59,7 @@ var TimelineBuilder = function (manager, config)
var onUpdateScope = GetValue(config, 'onUpdateScope', scope);
var onUpdateParams = GetValue(config, 'onUpdateParams', []);

timeline.setCallback('onUpdate', onUpdate, timelineArray.concat(onUpdateParams), onUpdateScope);
timeline.setCallback('onUpdate', onUpdate, onUpdateParams, onUpdateScope);
}

var onLoop = GetValue(config, 'onLoop', false);
Expand All @@ -73,7 +70,7 @@ var TimelineBuilder = function (manager, config)
var onLoopScope = GetValue(config, 'onLoopScope', scope);
var onLoopParams = GetValue(config, 'onLoopParams', []);

timeline.setCallback('onLoop', onLoop, timelineArray.concat(onLoopParams), onLoopScope);
timeline.setCallback('onLoop', onLoop, onLoopParams, onLoopScope);
}

var onYoyo = GetValue(config, 'onYoyo', false);
Expand All @@ -84,7 +81,7 @@ var TimelineBuilder = function (manager, config)
var onYoyoScope = GetValue(config, 'onYoyoScope', scope);
var onYoyoParams = GetValue(config, 'onYoyoParams', []);

timeline.setCallback('onYoyo', onYoyo, timelineArray.concat(null, onYoyoParams), onYoyoScope);
timeline.setCallback('onYoyo', onYoyo, onYoyoParams, onYoyoScope);
}

var onComplete = GetValue(config, 'onComplete', false);
Expand All @@ -95,7 +92,7 @@ var TimelineBuilder = function (manager, config)
var onCompleteScope = GetValue(config, 'onCompleteScope', scope);
var onCompleteParams = GetValue(config, 'onCompleteParams', []);

timeline.setCallback('onComplete', onComplete, timelineArray.concat(onCompleteParams), onCompleteScope);
timeline.setCallback('onComplete', onComplete, onCompleteParams, onCompleteScope);
}

// Tweens
Expand Down
7 changes: 1 addition & 6 deletions src/tweens/builders/TweenBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ var TweenBuilder = function (parent, config, defaults)

// Set the Callbacks
var scope = GetValue(config, 'callbackScope', tween);

// Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params
var tweenArray = [ tween, null ];

var callbacks = Tween.TYPES;

for (var i = 0; i < callbacks.length; i++)
Expand All @@ -116,8 +112,7 @@ var TweenBuilder = function (parent, config, defaults)
var callbackScope = GetValue(config, type + 'Scope', scope);
var callbackParams = GetValue(config, type + 'Params', []);

// The null is reset to be the Tween target
tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope);
tween.setCallback(type, callback, callbackParams, callbackScope);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tweens/tween/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ var Tween = new Class({
*/
setCallback: function (type, callback, params, scope)
{
this.callbacks[type] = { func: callback, scope: scope, params: params };
this.callbacks[type] = { func: callback, scope: scope, params: [ this, null ].concat(params) };

return this;
},
Expand Down