Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

container types implemented as array instead of hash

  • Loading branch information...
commit 828caafb8eada7fe79536ae0fa8c2a3412e178ba 1 parent 1d28d16
@hunterloftis authored
Showing with 9 additions and 21 deletions.
  1. +3 −9 build/cryo-0.0.2.js
  2. +3 −3 build/cryo-0.0.2.min.js
  3. +3 −9 lib/cryo.js
View
12 build/cryo-0.0.2.js
@@ -8,12 +8,7 @@
;(function() {
- var CONTAINER_TYPES = {
- 'object': function() { return {}; },
- 'array': function() { return {}; },
- 'date': function() { return {}; },
- 'function': function() { return {}; }
- };
+ var CONTAINER_TYPES = 'object array date function'.split(' ');
var REFERENCE_FLAG = '_CRYO_REF_';
var INFINITY_FLAG = '_CRYO_INFINITY_';
@@ -43,14 +38,13 @@
function cloneWithReferences(item, references, savedItems) {
savedItems = savedItems || [];
var type = typeOf(item);
- var constructor = CONTAINER_TYPES[type];
// can this object contain its own properties?
- if (constructor) {
+ if (CONTAINER_TYPES.indexOf(type) !== -1) {
var referenceIndex = savedItems.indexOf(item);
// do we need to store a new reference to this object?
if (referenceIndex === -1) {
- var clone = constructor();
+ var clone = {};
for (var key in item) {
if (item.hasOwnProperty(key)) {
clone[key] = cloneWithReferences(item[key], references, savedItems);
View
6 build/cryo-0.0.2.min.js
@@ -2,6 +2,6 @@
The MIT license.
@copyright Copyright (c) 2010 Skookum, skookum.com
*/
-(function(){function f(a){return"object"===typeof a?a instanceof Array?"array":a instanceof Date?"date":"object":typeof a}function m(a,b,c){c=c||[];var d=f(a);if(d=t[d]){var e=c.indexOf(a);if(-1===e){var d=d(),g;for(g in a)a.hasOwnProperty(g)&&(d[g]=m(a[g],b,c));e=b.push({contents:d,value:n(a)})-1;c[e]=a}return h+e}return n(a)}function p(a,b){if(j(a,h)){var c=parseInt(a.slice(h.length),10),d=b[c],c=q(d.value),d=d.contents,e;for(e in d)c[e]=p(d[e],b);return c}return q(a)}function n(a){var b=f(a);return"undefined"===
-b?r:"function"===b?k+a.toString():"date"===b?l+a.getTime():Infinity===a?s:a}function q(a){if("string"===f(a)){if(a===r)return;if(j(a,k)){a=a.slice(k.length);var b=a.indexOf("(")+1,c=a.indexOf(")",b),b=a.slice(b,c),c=a.indexOf("{")+1,d=a.lastIndexOf("}")-1;a=a.slice(c,d);return new Function(b,a)}if(j(a,l))return a=parseInt(a.slice(l.length),10),new Date(a);if(a===s)return Infinity}return a}function j(a,b){return"string"===f(a)&&a.slice(0,b.length)===b}var t={object:function(){return{}},array:function(){return{}},
-date:function(){return{}},"function":function(){return{}}},h="_CRYO_REF_",s="_CRYO_INFINITY_",k="_CRYO_FUNCTION_",r="_CRYO_UNDEFINED_",l="_CRYO_DATE_";Cryo={stringify:function(a){var b=[];a=m(a,b);return JSON.stringify({root:a,references:b})},parse:function(a){a=JSON.parse(a);return p(a.root,a.references)}};"undefined"!==typeof define&&define.amd?define("Cryo",[],function(){return Cryo}):"undefined"!==typeof module&&module.exports?module.exports=Cryo:this.Cryo=Cryo})();
+(function(){function f(a){return"object"===typeof a?a instanceof Array?"array":a instanceof Date?"date":"object":typeof a}function l(a,b,d){d=d||[];var c=f(a);if(-1!==s.indexOf(c)){c=d.indexOf(a);if(-1===c){var c={},e;for(e in a)a.hasOwnProperty(e)&&(c[e]=l(a[e],b,d));c=b.push({contents:c,value:m(a)})-1;d[c]=a}return g+c}return m(a)}function n(a,b){if(h(a,g)){var d=parseInt(a.slice(g.length),10),c=b[d],d=p(c.value),c=c.contents,e;for(e in c)d[e]=n(c[e],b);return d}return p(a)}function m(a){var b=
+f(a);return"undefined"===b?q:"function"===b?j+a.toString():"date"===b?k+a.getTime():Infinity===a?r:a}function p(a){if("string"===f(a)){if(a===q)return;if(h(a,j)){a=a.slice(j.length);var b=a.indexOf("(")+1,d=a.indexOf(")",b),b=a.slice(b,d),d=a.indexOf("{")+1,c=a.lastIndexOf("}")-1;a=a.slice(d,c);return new Function(b,a)}if(h(a,k))return a=parseInt(a.slice(k.length),10),new Date(a);if(a===r)return Infinity}return a}function h(a,b){return"string"===f(a)&&a.slice(0,b.length)===b}var s=["object","array",
+"date","function"],g="_CRYO_REF_",r="_CRYO_INFINITY_",j="_CRYO_FUNCTION_",q="_CRYO_UNDEFINED_",k="_CRYO_DATE_";Cryo={stringify:function(a){var b=[];a=l(a,b);return JSON.stringify({root:a,references:b})},parse:function(a){a=JSON.parse(a);return n(a.root,a.references)}};"undefined"!==typeof define&&define.amd?define("Cryo",[],function(){return Cryo}):"undefined"!==typeof module&&module.exports?module.exports=Cryo:this.Cryo=Cryo})();
View
12 lib/cryo.js
@@ -8,12 +8,7 @@
;(function() {
- var CONTAINER_TYPES = {
- 'object': function() { return {}; },
- 'array': function() { return {}; },
- 'date': function() { return {}; },
- 'function': function() { return {}; }
- };
+ var CONTAINER_TYPES = 'object array date function'.split(' ');
var REFERENCE_FLAG = '_CRYO_REF_';
var INFINITY_FLAG = '_CRYO_INFINITY_';
@@ -43,14 +38,13 @@
function cloneWithReferences(item, references, savedItems) {
savedItems = savedItems || [];
var type = typeOf(item);
- var constructor = CONTAINER_TYPES[type];
// can this object contain its own properties?
- if (constructor) {
+ if (CONTAINER_TYPES.indexOf(type) !== -1) {
var referenceIndex = savedItems.indexOf(item);
// do we need to store a new reference to this object?
if (referenceIndex === -1) {
- var clone = constructor();
+ var clone = {};
for (var key in item) {
if (item.hasOwnProperty(key)) {
clone[key] = cloneWithReferences(item[key], references, savedItems);
Please sign in to comment.
Something went wrong with that request. Please try again.