Skip to content

Commit 097af31

Browse files
authored
Merge pull request #2866 from m90/m90-dict-docs
Clean up and normalize reference for TypedDict classes
2 parents c9f325f + 6b97def commit 097af31

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

src/data/p5.TypedDict.js

+60-58
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* @for p5.TypedDict
55
* @requires core
66
*
7-
* This module defines the p5 methods for the p5 Dictionary classes
8-
* these classes StringDict and NumberDict are for storing and working
9-
* with key, value pairs
7+
* This module defines the p5 methods for the p5 Dictionary classes.
8+
* The classes StringDict and NumberDict are for storing and working
9+
* with key-value pairs.
1010
*/
1111

1212
'use strict';
@@ -15,8 +15,8 @@ var p5 = require('../core/core');
1515

1616
/**
1717
*
18-
* Creates a new instance of p5.StringDict using the key, value pair
19-
* or object you provide.
18+
* Creates a new instance of p5.StringDict using the key-value pair
19+
* or the object you provide.
2020
*
2121
* @method createStringDict
2222
* @for p5
@@ -30,6 +30,9 @@ var p5 = require('../core/core');
3030
* function setup() {
3131
* var myDictionary = createStringDict('p5', 'js');
3232
* print(myDictionary.hasKey('p5')); // logs true to console
33+
*
34+
* var anotherDictionary = createStringDict({ happy: 'coding' });
35+
* print(anotherDictionary.hasKey('happy')); // logs true to console
3336
* }
3437
* </code></div>
3538
*/
@@ -46,7 +49,7 @@ p5.prototype.createStringDict = function(key, value) {
4649

4750
/**
4851
*
49-
* Creates a new instance of p5.NumberDict using the key, value pair
52+
* Creates a new instance of p5.NumberDict using the key-value pair
5053
* or object you provide.
5154
*
5255
* @method createNumberDict
@@ -61,6 +64,9 @@ p5.prototype.createStringDict = function(key, value) {
6164
* function setup() {
6265
* var myDictionary = createNumberDict(100, 42);
6366
* print(myDictionary.hasKey(100)); // logs true to console
67+
*
68+
* var anotherDictionary = createNumberDict({ 200: 84 });
69+
* print(anotherDictionary.hasKey(200)); // logs true to console
6470
* }
6571
* </code></div>
6672
*/
@@ -77,8 +83,8 @@ p5.prototype.createNumberDict = function(key, value) {
7783

7884
/**
7985
*
80-
* Base class for all p5.Dictionary types. More specifically
81-
* typed Dictionary objects inherit from this
86+
* Base class for all p5.Dictionary types. Specifically
87+
* typed Dictionary classes inherit from this class.
8288
*
8389
* @class p5.TypedDict
8490
*
@@ -95,10 +101,10 @@ p5.TypedDict = function(key, value) {
95101
};
96102

97103
/**
98-
* Returns the number of key-value pairs currently in Dictionary object
104+
* Returns the number of key-value pairs currently stored in the Dictionary.
99105
*
100106
* @method size
101-
* @return {Integer} the number of key-value pairs in Dictionary object
107+
* @return {Integer} the number of key-value pairs in the Dictionary
102108
*
103109
* @example
104110
* <div class="norender">
@@ -107,7 +113,7 @@ p5.TypedDict = function(key, value) {
107113
* var myDictionary = createNumberDict(1, 10);
108114
* myDictionary.create(2, 20);
109115
* myDictionary.create(3, 30);
110-
* print(myDictionary.size()); // value of amt is 3
116+
* print(myDictionary.size()); // logs 3 to the console
111117
* }
112118
* </code></div>
113119
*
@@ -117,11 +123,11 @@ p5.TypedDict.prototype.size = function() {
117123
};
118124

119125
/**
120-
* Returns true if key exists in Dictionary
121-
* otherwise returns false
126+
* Returns true if the given key exists in the Dictionary,
127+
* otherwise returns false.
122128
*
123129
* @method hasKey
124-
* @param {Number|String} key that you want to access
130+
* @param {Number|String} key that you want to look up
125131
* @return {Boolean} whether that key exists in Dictionary
126132
*
127133
* @example
@@ -140,10 +146,10 @@ p5.TypedDict.prototype.hasKey = function(key) {
140146
};
141147

142148
/**
143-
* Returns value stored at supplied key.
149+
* Returns the value stored at the given key.
144150
*
145151
* @method get
146-
* @param {Number|String} key that you want to access
152+
* @param {Number|String} the key you want to access
147153
* @return {Number|String} the value stored at that key
148154
*
149155
* @example
@@ -167,8 +173,8 @@ p5.TypedDict.prototype.get = function(key) {
167173
};
168174

169175
/**
170-
* Changes the value of key if in it already exists in
171-
* in the Dictionary otherwise makes a new key-value pair
176+
* Updates the value associated with the given key in case it already exists
177+
* in the Dictionary. Otherwise a new key-value pair is added.
172178
*
173179
* @method set
174180
* @param {Number|String} key
@@ -180,8 +186,7 @@ p5.TypedDict.prototype.get = function(key) {
180186
* function setup() {
181187
* var myDictionary = createStringDict('p5', 'js');
182188
* myDictionary.set('p5', 'JS');
183-
* myDictionary.print();
184-
* // above logs "key: p5 - value: JS" to console
189+
* myDictionary.print(); // logs "key: p5 - value: JS" to console
185190
* }
186191
* </code></div>
187192
*
@@ -196,7 +201,7 @@ p5.TypedDict.prototype.set = function(key, value) {
196201
};
197202

198203
/**
199-
* private helper function to handle the user passing objects in
204+
* private helper function to handle the user passing in objects
200205
* during construction or calls to create()
201206
*/
202207

@@ -207,7 +212,7 @@ p5.TypedDict.prototype._addObj = function(obj) {
207212
};
208213

209214
/**
210-
* Creates a key-value pair in the Dictionary
215+
* Creates a new key-value pair in the Dictionary.
211216
*
212217
* @method create
213218
* @param {Number|String} key
@@ -243,7 +248,8 @@ p5.TypedDict.prototype.create = function(key, value) {
243248
};
244249

245250
/**
246-
* Empties Dictionary of all key-value pairs
251+
* Removes all previously stored key-value pairs from the Dictionary.
252+
*
247253
* @method clear
248254
* @example
249255
* <div class="norender">
@@ -263,7 +269,7 @@ p5.TypedDict.prototype.clear = function() {
263269
};
264270

265271
/**
266-
* Removes a key-value pair in the Dictionary
272+
* Removes the key-value pair stored at the given key from the Dictionary.
267273
*
268274
* @method remove
269275
* @param {Number|String} key for the pair to remove
@@ -293,7 +299,7 @@ p5.TypedDict.prototype.remove = function(key) {
293299
};
294300

295301
/**
296-
* Logs the list of items currently in the Dictionary to the console
302+
* Logs the set of items currently stored in the Dictionary to the console.
297303
*
298304
* @method print
299305
*
@@ -317,8 +323,7 @@ p5.TypedDict.prototype.print = function() {
317323
};
318324

319325
/**
320-
* Converts the Dictionary into a CSV file for local
321-
* storage.
326+
* Converts the Dictionary into a CSV file for local download.
322327
*
323328
* @method saveTable
324329
* @example
@@ -329,9 +334,9 @@ p5.TypedDict.prototype.print = function() {
329334
* .mousePressed(function() {
330335
* createStringDict({
331336
* john: 1940,
332-
paul: 1942,
333-
george: 1943,
334-
ringo: 1940
337+
* paul: 1942,
338+
* george: 1943,
339+
* ringo: 1940
335340
* }).saveTable('beatles');
336341
* });
337342
* </code>
@@ -350,8 +355,7 @@ p5.TypedDict.prototype.saveTable = function(filename) {
350355
};
351356

352357
/**
353-
* Converts the Dictionary into a JSON file for local
354-
* storage.
358+
* Converts the Dictionary into a JSON file for local download.
355359
*
356360
* @method saveJSON
357361
* @example
@@ -362,9 +366,9 @@ p5.TypedDict.prototype.saveTable = function(filename) {
362366
* .mousePressed(function() {
363367
* createStringDict({
364368
* john: 1940,
365-
paul: 1942,
366-
george: 1943,
367-
ringo: 1940
369+
* paul: 1942,
370+
* george: 1943,
371+
* ringo: 1940
368372
* }).saveJSON('beatles');
369373
* });
370374
* </code>
@@ -386,8 +390,7 @@ p5.TypedDict.prototype._validate = function(value) {
386390

387391
/**
388392
*
389-
* A Dictionary class for Strings.
390-
*
393+
* A simple Dictionary class for Strings.
391394
*
392395
* @class p5.StringDict
393396
* @extends p5.TypedDict
@@ -408,7 +411,6 @@ p5.StringDict.prototype._validate = function(value) {
408411
*
409412
* A simple Dictionary class for Numbers.
410413
*
411-
*
412414
* @class p5.NumberDict
413415
* @extends p5.TypedDict
414416
*
@@ -430,19 +432,19 @@ p5.NumberDict.prototype._validate = function(value) {
430432
};
431433

432434
/**
433-
* Add to a value stored at a certain key
434-
* The sum is stored in that location in the Dictionary.
435+
* Add the given number to the value currently stored at the given key.
436+
* The sum then replaces the value previously stored in the Dictionary.
435437
*
436438
* @method add
437-
* @param {Number} Key for value you wish to add to
438-
* @param {Number} Amount to add to the value
439+
* @param {Number} Key for the value you wish to add to
440+
* @param {Number} Number to add to the value
439441
* @example
440442
* <div class='norender'>
441443
* <code>
442444
* function setup() {
443445
* var myDictionary = createNumberDict(2, 5);
444446
* myDictionary.add(2, 2);
445-
* console.log(myDictionary.get(2)); // logs 7 to console.
447+
* print(myDictionary.get(2)); // logs 7 to console.
446448
* }
447449
* </code></div>
448450
*
@@ -458,19 +460,19 @@ p5.NumberDict.prototype.add = function(key, amount) {
458460
};
459461

460462
/**
461-
* Subtract from a value stored at a certain key
462-
* The difference is stored in that location in the Dictionary.
463+
* Subtract the given number from the value currently stored at the given key.
464+
* The difference then replaces the value previously stored in the Dictionary.
463465
*
464466
* @method sub
465-
* @param {Number} Key for value you wish to subtract from
466-
* @param {Number} Amount to subtract from the value
467+
* @param {Number} Key for the value you wish to subtract from
468+
* @param {Number} Number to subtract from the value
467469
* @example
468470
* <div class='norender'>
469471
* <code>
470472
* function setup() {
471473
* var myDictionary = createNumberDict(2, 5);
472474
* myDictionary.sub(2, 2);
473-
* console.log(myDictionary.get(2)); // logs 3 to console.
475+
* print(myDictionary.get(2)); // logs 3 to console.
474476
* }
475477
* </code></div>
476478
*
@@ -482,8 +484,8 @@ p5.NumberDict.prototype.sub = function(key, amount) {
482484
};
483485

484486
/**
485-
* Multiply a value stored at a certain key
486-
* The product is stored in that location in the Dictionary.
487+
* Multiply the given number with the value currently stored at the given key.
488+
* The product then replaces the value previously stored in the Dictionary.
487489
*
488490
* @method mult
489491
* @param {Number} Key for value you wish to multiply
@@ -494,7 +496,7 @@ p5.NumberDict.prototype.sub = function(key, amount) {
494496
* function setup() {
495497
* var myDictionary = createNumberDict(2, 4);
496498
* myDictionary.mult(2, 2);
497-
* console.log(myDictionary.get(2)); // logs 8 to console.
499+
* print(myDictionary.get(2)); // logs 8 to console.
498500
* }
499501
* </code></div>
500502
*
@@ -510,8 +512,8 @@ p5.NumberDict.prototype.mult = function(key, amount) {
510512
};
511513

512514
/**
513-
* Divide a value stored at a certain key
514-
* The quotient is stored in that location in the Dictionary.
515+
* Divide the given number with the value currently stored at the given key.
516+
* The quotient then replaces the value previously stored in the Dictionary.
515517
*
516518
* @method div
517519
* @param {Number} Key for value you wish to divide
@@ -522,7 +524,7 @@ p5.NumberDict.prototype.mult = function(key, amount) {
522524
* function setup() {
523525
* var myDictionary = createNumberDict(2, 8);
524526
* myDictionary.div(2, 2);
525-
* console.log(myDictionary.get(2)); // logs 4 to console.
527+
* print(myDictionary.get(2)); // logs 4 to console.
526528
* }
527529
* </code></div>
528530
*
@@ -561,7 +563,7 @@ p5.NumberDict.prototype._valueTest = function(flip) {
561563
};
562564

563565
/**
564-
* Return the lowest value.
566+
* Return the lowest number currently stored in the Dictionary.
565567
*
566568
* @method minValue
567569
* @return {Number}
@@ -582,7 +584,7 @@ p5.NumberDict.prototype.minValue = function() {
582584
};
583585

584586
/**
585-
* Return the highest value.
587+
* Return the highest number currently stored in the Dictionary.
586588
*
587589
* @method maxValue
588590
* @return {Number}
@@ -626,7 +628,7 @@ p5.NumberDict.prototype._keyTest = function(flip) {
626628
};
627629

628630
/**
629-
* Return the lowest key.
631+
* Return the lowest key currently used in the Dictionary.
630632
*
631633
* @method minKey
632634
* @return {Number}
@@ -647,7 +649,7 @@ p5.NumberDict.prototype.minKey = function() {
647649
};
648650

649651
/**
650-
* Return the highest key.
652+
* Return the highest key currently used in the Dictionary.
651653
*
652654
* @method maxKey
653655
* @return {Number}

0 commit comments

Comments
 (0)