minor changes in Collection.js, mostly documentation

This commit is contained in:
rlx 2012-03-29 20:01:05 +00:00
parent 4b59c9a2a9
commit 9265efe61a

View file

@ -28,7 +28,7 @@ Ox.contains <f> Tests if a collection contains a value
@*/ @*/
Ox.contains = function(col, val) { Ox.contains = function(col, val) {
/* /*
// fixme: rename to Ox.has or Ox.isIn? // fixme: rename to Ox.has or Ox.in?
// then it'd become convenient for arrays // then it'd become convenient for arrays
*/ */
return (Ox.isObject(col) ? Ox.values(col) : col).indexOf(val) > -1; return (Ox.isObject(col) ? Ox.values(col) : col).indexOf(val) > -1;
@ -45,7 +45,6 @@ Ox.copy <f> Returns a (shallow or deep) copy of an object or array
@*/ @*/
Ox.copy = Ox.clone = function(col, deep) { Ox.copy = Ox.clone = function(col, deep) {
// fixme: copy or clone? // fixme: copy or clone?
// fixme: is there any use case for shallow copy?
var ret = Ox.isArray(col) ? [] : {}; var ret = Ox.isArray(col) ? [] : {};
if (deep) { if (deep) {
Ox.forEach(col, function(val, key) { Ox.forEach(col, function(val, key) {
@ -150,8 +149,8 @@ Ox.forEach <f> forEach loop
Returning <code>false</code> from the iterator function acts like a Returning <code>false</code> from the iterator function acts like a
<code>break</code> statement (unlike <code>[].forEach()</code>, like <code>break</code> statement (unlike <code>[].forEach()</code>, like
<code>$.each()</code>). The arguments of the iterator function are <code>$.each()</code>). The arguments of the iterator function are
<code>(value, key)</code> (like <code>[].forEach()</code>, unlike <code>(value, key, index)</code> (more like <code>[].forEach()</code>
<code>$.each()</code>). than like <code>$.each()</code>).
(collection, callback) <a|o|s> The collection (collection, callback) <a|o|s> The collection
(collection, callback, includePrototype) <a|o|s> The collection (collection, callback, includePrototype) <a|o|s> The collection
collection <a|o|s> An array, object or string collection <a|o|s> An array, object or string
@ -210,6 +209,7 @@ Ox.getIndexById <f> Returns the first array index of an object with a given id
0 0
@*/ @*/
Ox.getIndexById = function(arr, id) { Ox.getIndexById = function(arr, id) {
// FIXME: shouldn't this be merged into Ox.getIndex?
return Ox.getIndex(arr, 'id', id); return Ox.getIndex(arr, 'id', id);
}; };
@ -239,6 +239,7 @@ Ox.getObjectById <f> Returns the first object in an array with a given id
{id: "foo", str: "Foo"} {id: "foo", str: "Foo"}
@*/ @*/
Ox.getObjectById = function(arr, id) { Ox.getObjectById = function(arr, id) {
// FIXME: shouldn't this be merged into Ox.getObject?
return Ox.getObject(arr, 'id', id); return Ox.getObject(arr, 'id', id);
}; };
@ -324,7 +325,7 @@ Ox.isEmpty <f> Returns true if a collection is empty
false false
@*/ @*/
Ox.isEmpty = function(val) { Ox.isEmpty = function(val) {
return Ox.len(val) == 0; return Ox.len(val) === 0;
}; };
/*@ /*@
@ -480,6 +481,7 @@ Ox.map = function(obj, fn) {
var isObject = Ox.isObject(obj), var isObject = Ox.isObject(obj),
ret = isObject ? {} : []; ret = isObject ? {} : [];
Ox.forEach(obj, function(val, key) { Ox.forEach(obj, function(val, key) {
// FIXME: is there any reason for this strange assignment?
var map; var map;
if ((map = fn(val, key)) !== null) { if ((map = fn(val, key)) !== null) {
ret[isObject ? key : ret.length] = map; ret[isObject ? key : ret.length] = map;
@ -644,14 +646,14 @@ Ox.sum = function(col) {
return sum; return sum;
}; };
Ox.toArray = function(obj) { /*@
// fixme: can this be thrown out? Ox.toArray <f> Wraps any non-array in an array.
/*
>>> Ox.toArray('foo') >>> Ox.toArray('foo')
['foo'] ['foo']
>>> Ox.toArray(['foo']) >>> Ox.toArray(['foo'])
['foo'] ['foo']
*/ @*/
Ox.toArray = function(obj) {
var arr; var arr;
if (Ox.isArray(obj)) { if (Ox.isArray(obj)) {
arr = obj; arr = obj;
@ -684,7 +686,7 @@ Ox.values = function(col) {
}; };
/*@ /*@
Ox.walk <f> Recursively walk a tree-like key/value store Ox.walk <f> Recursively walk a tree of key/value pairs
<script> <script>
Ox.test.number = 0; Ox.test.number = 0;
Ox.walk({a: 1, b: {c: 2, d: 3}}, function (v) { Ox.walk({a: 1, b: {c: 2, d: 3}}, function (v) {