Skip to content

Commit c90a384

Browse files
committed
DataManager.Events.DESTROY is a new event that the Data Manager will _listen_ for from its parent and then call its own destroy method when received.
1 parent fc6240c commit c90a384

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

src/data/DataManager.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ var DataManager = new Class({
7979
* ```
8080
*
8181
* You can also modify it directly:
82-
*
82+
*
8383
* ```javascript
8484
* this.data.values.gold += 1000;
8585
* ```
8686
*
8787
* Doing so will emit a `setdata` event from the parent of this Data Manager.
88-
*
88+
*
8989
* Do not modify this object directly. Adding properties directly to this object will not
9090
* emit any events. Always use `DataManager.set` to create new items the first time around.
9191
*
@@ -109,27 +109,27 @@ var DataManager = new Class({
109109

110110
if (!parent.hasOwnProperty('sys') && this.events)
111111
{
112-
this.events.once('destroy', this.destroy, this);
112+
this.events.once(Events.DESTROY, this.destroy, this);
113113
}
114114
},
115115

116116
/**
117117
* Retrieves the value for the given key, or undefined if it doesn't exist.
118118
*
119119
* You can also access values via the `values` object. For example, if you had a key called `gold` you can do either:
120-
*
120+
*
121121
* ```javascript
122122
* this.data.get('gold');
123123
* ```
124124
*
125125
* Or access the value directly:
126-
*
126+
*
127127
* ```javascript
128128
* this.data.values.gold;
129129
* ```
130130
*
131131
* You can also pass in an array of keys, in which case an array of values will be returned:
132-
*
132+
*
133133
* ```javascript
134134
* this.data.get([ 'gold', 'armor', 'health' ]);
135135
* ```
@@ -214,7 +214,7 @@ var DataManager = new Class({
214214

215215
/**
216216
* Sets a value for the given key. If the key doesn't already exist in the Data Manager then it is created.
217-
*
217+
*
218218
* ```javascript
219219
* data.set('name', 'Red Gem Stone');
220220
* ```
@@ -226,13 +226,13 @@ var DataManager = new Class({
226226
* ```
227227
*
228228
* To get a value back again you can call `get`:
229-
*
229+
*
230230
* ```javascript
231231
* data.get('gold');
232232
* ```
233-
*
233+
*
234234
* Or you can access the value directly via the `values` property, where it works like any other variable:
235-
*
235+
*
236236
* ```javascript
237237
* data.values.gold += 50;
238238
* ```
@@ -281,9 +281,9 @@ var DataManager = new Class({
281281

282282
/**
283283
* Increase a value for the given key. If the key doesn't already exist in the Data Manager then it is increased from 0.
284-
*
284+
*
285285
* When the value is first set, a `setdata` event is emitted.
286-
*
286+
*
287287
* @method Phaser.Data.DataManager#inc
288288
* @fires Phaser.Data.Events#SET_DATA
289289
* @fires Phaser.Data.Events#CHANGE_DATA
@@ -320,9 +320,9 @@ var DataManager = new Class({
320320

321321
/**
322322
* Toggle a boolean value for the given key. If the key doesn't already exist in the Data Manager then it is toggled from false.
323-
*
323+
*
324324
* When the value is first set, a `setdata` event is emitted.
325-
*
325+
*
326326
* @method Phaser.Data.DataManager#toggle
327327
* @fires Phaser.Data.Events#SET_DATA
328328
* @fires Phaser.Data.Events#CHANGE_DATA
@@ -382,7 +382,7 @@ var DataManager = new Class({
382382
Object.defineProperty(this.values, key, {
383383

384384
enumerable: true,
385-
385+
386386
configurable: true,
387387

388388
get: function ()
@@ -482,9 +482,9 @@ var DataManager = new Class({
482482
*
483483
* If the key is found in this Data Manager it is removed from the internal lists and a
484484
* `removedata` event is emitted.
485-
*
485+
*
486486
* You can also pass in an array of keys, in which case all keys in the array will be removed:
487-
*
487+
*
488488
* ```javascript
489489
* this.data.remove([ 'gold', 'armor', 'health' ]);
490490
* ```
@@ -576,7 +576,7 @@ var DataManager = new Class({
576576

577577
/**
578578
* Determines whether the given key is set in this Data Manager.
579-
*
579+
*
580580
* Please note that the keys are case-sensitive and must be valid JavaScript Object property strings.
581581
* This means the keys `gold` and `Gold` are treated as two unique values within the Data Manager.
582582
*

src/data/events/DESTROY_EVENT.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Data Manager Destroy Event.
9+
*
10+
* The Data Manager will listen for the destroy event from its parent, and then close itself down.
11+
*
12+
* @event Phaser.Data.Events#DESTROY
13+
* @since 3.50.0
14+
*/
15+
module.exports = 'destroy';

src/data/events/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
CHANGE_DATA: require('./CHANGE_DATA_EVENT'),
1414
CHANGE_DATA_KEY: require('./CHANGE_DATA_KEY_EVENT'),
15+
DESTROY: require('./DESTROY_EVENT'),
1516
REMOVE_DATA: require('./REMOVE_DATA_EVENT'),
1617
SET_DATA: require('./SET_DATA_EVENT')
1718

0 commit comments

Comments
 (0)