Skip to content

Commit f4f88a6

Browse files
authored
Merge pull request phaserjs#3425 from orblazer/fix-types
Add callbacks types
2 parents 6d8b702 + fa13b59 commit f4f88a6

40 files changed

Lines changed: 395 additions & 149 deletions

src/actions/Call.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
/**
8+
* @callback CallCallback
9+
*
10+
* @param {Phaser.GameObjects.GameObject} item - [description]
11+
*/
12+
713
/**
814
* Takes an array of objects and passes each of them to the given callback.
915
*
1016
* @function Phaser.Actions.Call
1117
* @since 3.0.0
12-
*
18+
*
1319
* @param {array|Phaser.GameObjects.GameObject[]} items - The array of items to be updated by this action.
14-
* @param {function} callback - The callback to be invoked. It will be passed just one argument: the item from the array.
20+
* @param {CallCallback} callback - The callback to be invoked. It will be passed just one argument: the item from the array.
1521
* @param {object} context - The scope in which the callback will be invoked.
1622
*
1723
* @return {array} The array of objects that was passed to this Action.

src/actions/SetHitArea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*
1010
* @function Phaser.Actions.SetHitArea
1111
* @since 3.0.0
12-
*
12+
*
1313
* @param {array} items - An array of Game Objects. The contents of this array are updated by this Action.
1414
* @param {any} hitArea - [description]
15-
* @param {function} hitAreaCallback - [description]
15+
* @param {HitAreaCallback} hitAreaCallback - [description]
1616
*
1717
* @return {array} The array of Game Objects that was passed to this Action.
1818
*/

src/boot/Config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ var ValueToColor = require('../display/color/ValueToColor');
1818
* @callback NOOP
1919
*/
2020

21+
/**
22+
* @callback BootCallback
23+
*
24+
* @param {Phaser.Game} game - [description]
25+
*/
26+
2127
/**
2228
* @typedef {object} FPSConfig
2329
*
@@ -86,8 +92,8 @@ var ValueToColor = require('../display/color/ValueToColor');
8692
* @property {boolean} [powerPreference='default'] - "high-performance", "low-power" or "default"
8793
* @property {string|number} [backgroundColor=0x000000] - [description]
8894
* @property {object} [?callbacks] - [description]
89-
* @property {function} [callbacks.preBoot=NOOP] - [description]
90-
* @property {function} [callbacks.postBoot=NOOP] - [description]
95+
* @property {BootCallback} [callbacks.preBoot=NOOP] - [description]
96+
* @property {BootCallback} [callbacks.postBoot=NOOP] - [description]
9197
* @property {LoaderConfig} [?loader] - [description]
9298
* @property {object} [?images] - [description]
9399
* @property {string} [images.default] - [description]

src/boot/Game.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var TextureManager = require('../textures/TextureManager');
2525
var TimeStep = require('./TimeStep');
2626
var VisibilityHandler = require('./VisibilityHandler');
2727

28+
/**
29+
* @callback GameStepCallback
30+
*/
31+
2832
/**
2933
* @classdesc
3034
* The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible
@@ -232,7 +236,7 @@ var Game = new Class({
232236
* It is set automatically when the Game boot process has completed.
233237
*
234238
* @name Phaser.Game#onStepCallback
235-
* @type {function}
239+
* @type {GameStepCallback}
236240
* @private
237241
* @since 3.0.0
238242
*/

src/boot/TimeStep.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
2020

2121
// http://www.testufo.com/#test=animation-time-graph
2222

23+
/**
24+
* @callback TimeStepCallback
25+
*
26+
* @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
27+
* @param {number} average - The Delta Average.
28+
* @param {number} interpolation - Interpolation - how far between what is expected and where we are?
29+
*/
30+
2331
/**
2432
* @classdesc
2533
* [description]
@@ -78,7 +86,7 @@ var TimeStep = new Class({
7886
* @since 3.0.0
7987
*/
8088
this.running = false;
81-
89+
8290
/**
8391
* The minimum fps rate you want the Time Step to run at.
8492
*
@@ -90,7 +98,7 @@ var TimeStep = new Class({
9098

9199
/**
92100
* The target fps rate for the Time Step to run at.
93-
*
101+
*
94102
* Setting this value will not actually change the speed at which the browser runs, that is beyond
95103
* the control of Phaser. Instead, it allows you to determine performance issues and if the Time Step
96104
* is spiraling out of control.
@@ -154,7 +162,7 @@ var TimeStep = new Class({
154162
/**
155163
* A callback to be invoked each time the Time Step steps.
156164
*
157-
* @property {function} callback
165+
* @property {TimeStepCallback} callback
158166
* @default NOOP
159167
* @since 3.0.0
160168
*/
@@ -379,7 +387,7 @@ var TimeStep = new Class({
379387
* @method Phaser.Boot.TimeStep#start
380388
* @since 3.0.0
381389
*
382-
* @param {function} callback - The callback to be invoked each time the Time Step steps.
390+
* @param {TimeStepCallback} callback - The callback to be invoked each time the Time Step steps.
383391
*/
384392
start: function (callback)
385393
{
@@ -544,7 +552,7 @@ var TimeStep = new Class({
544552
if (this.running)
545553
{
546554
this.raf.stop();
547-
555+
548556
this.running = false;
549557
}
550558
},

src/create/GenerateTexture.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ var Arne16 = require('./palettes/Arne16');
88
var CanvasPool = require('../display/canvas/CanvasPool');
99
var GetValue = require('../utils/object/GetValue');
1010

11+
/**
12+
* @callback GenerateTextureRendererCallback
13+
*
14+
* @param {HTMLCanvasElement} canvas - [description]
15+
* @param {CanvasRenderingContext2D} context - [description]
16+
*/
17+
1118
/**
1219
* @typedef {object} GenerateTextureConfig
1320
*
@@ -18,8 +25,8 @@ var GetValue = require('../utils/object/GetValue');
1825
* @property {number} [pixelHeight=1] - [description]
1926
* @property {boolean} [resizeCanvas=true] - [description]
2027
* @property {boolean} [clearCanvas=true] - [description]
21-
* @property {function} [preRender] - [description]
22-
* @property {function} [postRender] - [description]
28+
* @property {GenerateTextureRendererCallback} [preRender] - [description]
29+
* @property {GenerateTextureRendererCallback} [postRender] - [description]
2330
*/
2431

2532
/**

src/data/DataManager.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
var Class = require('../utils/Class');
88

9+
/**
10+
* @callback DataEachCallback
11+
*
12+
* @param {any} parent - [description]
13+
* @param {string} key - [description]
14+
* @param {any} value - [description]
15+
* @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the game object, key, and data.
16+
*/
17+
918
/**
1019
* @classdesc
1120
* The Data Component features a means to store pieces of data specific to a Game Object, System or Plugin.
@@ -199,7 +208,7 @@ var DataManager = new Class({
199208
* @method Phaser.Data.DataManager#each
200209
* @since 3.0.0
201210
*
202-
* @param {function} callback - The function to call.
211+
* @param {DataEachCallback} callback - The function to call.
203212
* @param {object} [scope] - Value to use as `this` when executing callback.
204213
* @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the game object, key, and data.
205214
*

src/dom/DOMContentLoaded.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
var OS = require('../device/OS');
88

9+
/**
10+
* @callback ContentLoadedCallback
11+
*/
12+
913
/**
1014
* Inspects the readyState of the document. If the document is already complete then it invokes the given callback.
1115
* If not complete it sets up several event listeners such as `deviceready`, and once those fire, it invokes the callback.
@@ -14,7 +18,7 @@ var OS = require('../device/OS');
1418
* @function Phaser.DOM.DOMContentLoaded
1519
* @since 3.0.0
1620
*
17-
* @param {function} callback - The callback to be invoked when the device is ready and the DOM content is loaded.
21+
* @param {ContentLoadedCallback} callback - The callback to be invoked when the device is ready and the DOM content is loaded.
1822
*/
1923
var DOMContentLoaded = function (callback)
2024
{

src/dom/RequestAnimationFrame.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var RequestAnimationFrame = new Class({
3737
* The callback to be invoked each step.
3838
*
3939
* @name Phaser.DOM.RequestAnimationFrame#callback
40-
* @type {function}
40+
* @type {FrameRequestCallback}
4141
* @since 3.0.0
4242
*/
4343
this.callback = NOOP;
@@ -89,7 +89,7 @@ var RequestAnimationFrame = new Class({
8989
* Updates the local tick value, invokes the callback and schedules another call to requestAnimationFrame.
9090
*
9191
* @name Phaser.DOM.RequestAnimationFrame#step
92-
* @type {function}
92+
* @type {FrameRequestCallback}
9393
* @since 3.0.0
9494
*/
9595
this.step = function step (timestamp)
@@ -134,7 +134,7 @@ var RequestAnimationFrame = new Class({
134134
* @method Phaser.DOM.RequestAnimationFrame#start
135135
* @since 3.0.0
136136
*
137-
* @param {function} callback - The callback to invoke each step.
137+
* @param {FrameRequestCallback} callback - The callback to invoke each step.
138138
* @param {boolean} forceSetTimeOut - Should it use SetTimeout, even if RAF is available?
139139
*/
140140
start: function (callback, forceSetTimeOut)

src/gameobjects/GameObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ var GameObject = new Class({
254254
* @since 3.0.0
255255
*
256256
* @param {any} [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
257-
* @param {function} [callback] - A callback to be invoked when the Game Object is interacted with.
257+
* @param {HitAreaCallback} [callback] - A callback to be invoked when the Game Object is interacted with.
258258
* @param {boolean} [dropZone=false] - Should this Game Object be treated as a drop zone target?
259259
*
260260
* @return {Phaser.GameObjects.GameObject} This GameObject.

0 commit comments

Comments
 (0)