Permalink
Browse files

[minor] Minor style changes to prototype definition(s)

  • Loading branch information...
1 parent 6fd7e4e commit 21b9ae37e849cc85e203051cf7a709154baed7c2 @indexzero indexzero committed Oct 1, 2011
Showing with 44 additions and 40 deletions.
  1. +1 −1 lib/resourceful.js
  2. +43 −39 lib/resourceful/cache.js
View
2 lib/resourceful.js
@@ -2,7 +2,7 @@ var resourceful = exports;
resourceful.Cache = require('./resourceful/cache').Cache;
resourceful.cache = require('./resourceful/cache').cache;
-resourceful.caches = require('./resourceful/cache').caches;
+resourceful.caches = require('./resourceful/cache').caches;
resourceful.Resource = require('./resourceful/resource').Resource;
resourceful.define = require('./resourceful/core').define;
View
82 lib/resourceful/cache.js
@@ -19,45 +19,49 @@ exports.Cache = function (options) {
resourceful.caches.push(this);
};
-exports.Cache.prototype = {
- get: function (id) {
- var that = this;
- if (!resourceful.cache) { return }
- if (!id) { return }
- else if (Array.isArray(id)) {
- return id.map(function (k) {
- return that.store[k.toString()];
- });
- } else {
- return this.store[id.toString()];
- }
- },
- put: function (id, obj) {
- if (!resourceful.cache) { return }
- if (!this.has(id)) { this.size ++ }
- this.store[id] = obj;
- },
- update: function (id, obj) {
- if (!resourceful.cache) { return }
- if (id in this.store) {
- for (var k in obj) {
- try { this.store[id][k] = obj[k]; }
- catch (ex) { }
- }
- }
- },
- clear: function (id) {
- if (!resourceful.cache) { return }
- if (id) {
- this.size --;
- delete(this.store[id]);
- } else {
- this.size = 0;
- this.store = {};
+exports.Cache.prototype.get = function (id) {
+ var that = this;
+ if (!resourceful.cache) { return }
+ if (!id) { return }
+ else if (Array.isArray(id)) {
+ return id.map(function (k) {
+ return that.store[k.toString()];
+ });
+ }
+ else {
+ return this.store[id.toString()];
+ }
+};
+
+exports.Cache.prototype.put = function (id, obj) {
+ if (!resourceful.cache) { return }
+ if (!this.has(id)) { this.size++ }
+ this.store[id] = obj;
+};
+
+exports.Cache.prototype.update = function (id, obj) {
+ if (!resourceful.cache) { return }
+ if (id in this.store) {
+ for (var k in obj) {
+ try { this.store[id][k] = obj[k]; }
+ catch (ex) { }
}
- },
- has: function (id) {
- if (!resourceful.cache) { return }
- return id in this.store;
}
};
+
+exports.Cache.prototype.clear = function (id) {
+ if (!resourceful.cache) { return }
+ if (id) {
+ this.size --;
+ delete(this.store[id]);
+ }
+ else {
+ this.size = 0;
+ this.store = {};
+ }
+};
+
+exports.Cache.prototype.has = function (id) {
+ if (!resourceful.cache) { return }
+ return id in this.store;
+};

0 comments on commit 21b9ae3

Please sign in to comment.