usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [36/41] git commit: Revert "removing 2 more as-yet unused files"
Date Tue, 11 Feb 2014 23:21:20 GMT
Revert "removing 2 more as-yet unused files"

This reverts commit 2ab8ec4d2f69bf4b35ddf5087c47009078b404c5.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a0a585ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a0a585ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a0a585ba

Branch: refs/heads/master
Commit: a0a585ba38cdb605f32cd04b1bcd1650da274eb8
Parents: 2ab8ec4
Author: ryan bridges <rbridges@apigee.com>
Authored: Tue Feb 11 11:52:17 2014 -0500
Committer: ryan bridges <rbridges@apigee.com>
Committed: Tue Feb 11 11:52:17 2014 -0500

----------------------------------------------------------------------
 sdks/html5-javascript/Gruntfile.js              |   2 +
 sdks/html5-javascript/lib/modules/util/Event.js |  33 +++++
 .../lib/modules/util/Storable.js                |  88 +++++++++++++
 sdks/html5-javascript/usergrid.js               | 132 +++++++++++++++++++
 sdks/html5-javascript/usergrid.min.js           |   4 +-
 5 files changed, 257 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0a585ba/sdks/html5-javascript/Gruntfile.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/Gruntfile.js b/sdks/html5-javascript/Gruntfile.js
index d48a950..cfa39e3 100644
--- a/sdks/html5-javascript/Gruntfile.js
+++ b/sdks/html5-javascript/Gruntfile.js
@@ -1,8 +1,10 @@
 module.exports = function(grunt) {
 	var files = [
+        "lib/modules/util/Event.js",
         "lib/modules/util/Logger.js",
         "lib/modules/util/Promise.js",
         "lib/modules/util/Ajax.js",
+        "lib/modules/util/Storable.js",
         "lib/Usergrid.js",
 		"lib/modules/Client.js",
 		"lib/modules/Entity.js",

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0a585ba/sdks/html5-javascript/lib/modules/util/Event.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/util/Event.js b/sdks/html5-javascript/lib/modules/util/Event.js
new file mode 100644
index 0000000..146d03e
--- /dev/null
+++ b/sdks/html5-javascript/lib/modules/util/Event.js
@@ -0,0 +1,33 @@
+var UsergridEventable	= function(){
+    throw Error("'UsergridEventable' is not intended to be invoked directly")
+}
+UsergridEventable.prototype	= {
+    bind	: function(event, fn){
+        this._events = this._events || {};
+        this._events[event] = this._events[event]	|| [];
+        this._events[event].push(fn);
+    },
+    unbind	: function(event, fn){
+        this._events = this._events || {};
+        if( event in this._events === false  )	return;
+        this._events[event].splice(this._events[event].indexOf(fn), 1);
+    },
+    trigger	: function(event /* , args... */){
+        this._events = this._events || {};
+        if( event in this._events === false  )	return;
+        for(var i = 0; i < this._events[event].length; i++){
+            this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
+        }
+    }
+};
+UsergridEventable.mixin	= function(destObject){
+    var props	= ['bind', 'unbind', 'trigger'];
+    for(var i = 0; i < props.length; i ++){
+        if(props[i] in destObject.prototype){
+            console.warn("overwriting '"+props[i]+"' on '"+destObject.name+"'.");
+            console.warn("the previous version can be found at '_"+props[i]+"' on '"+destObject.name+"'.");
+            destObject.prototype['_'+props[i]]=destObject.prototype[props[i]];
+        }
+        destObject.prototype[props[i]]	= UsergridEventable.prototype[props[i]];
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0a585ba/sdks/html5-javascript/lib/modules/util/Storable.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/util/Storable.js b/sdks/html5-javascript/lib/modules/util/Storable.js
new file mode 100644
index 0000000..5c4da2e
--- /dev/null
+++ b/sdks/html5-javascript/lib/modules/util/Storable.js
@@ -0,0 +1,88 @@
+function UsergridStorable(storage, keyPrefix){
+    //throw Error("'UsergridStorable' is not intended to be invoked directly")
+}
+UsergridStorable.prototype.setStorage = function(storage) {
+    if(!(storage instanceof Storage)){
+        console.warn("parameter passed to 'setStorage' is not a browser Storage interface.
using sessionStorage");
+        storage=sessionStorage;
+    }
+    return this._storage=storage;
+};
+UsergridStorable.prototype.getStorage = function() {
+    if(!(this._storage instanceof Storage)){
+        console.warn("parameter passed to 'setStorage' is not a browser Storage interface.
using sessionStorage");
+        this._storage=sessionStorage;
+    }
+    return this._storage;
+};
+UsergridStorable.prototype.getStorageKey = function(key) {
+    if(!this._keyPrefix)this._keyPrefix='usergrid_js_sdk_';
+    return this._keyPrefix+key;
+};
+UsergridStorable.prototype.get=function(key){
+    var value;
+    if(arguments.length>1){
+        key=[].slice.call(arguments).reduce(function(p,c,i,a){
+            if(c instanceof Array){
+                p= p.concat(c);
+            }else{
+                p.push(c);
+            }
+            return p;
+        },[]);
+    }
+    if(this._storage instanceof Storage){
+        if(key instanceof Array){
+            var self=this;
+            value=key.map(function(k){return self.get(k)});
+        }else if("undefined" !== typeof key){
+            this[key]=JSON.parse(this.getStorage().getItem(this.getStorageKey(key)));
+            value=this[key];
+        }
+    }
+    return value;
+}
+UsergridStorable.prototype.set=function(key, value){
+    if(this._storage instanceof Storage){
+        if(value){
+            this[key]=JSON.stringify(value);
+            this.getStorage().setItem(this.getStorageKey(key),this[key]);
+        }else{
+            delete this[key];
+            this.getStorage().removeItem(this.getStorageKey(key));
+        }
+    }
+}
+/*
+ *  A public method to store the OAuth token for later use - uses localstorage if available
+ *
+ *  @method setToken
+ *  @public
+ *  @params {string} token
+ *  @return none
+ */
+UsergridStorable.prototype.setToken = function (token) {
+    return this.set('token', token);
+};
+
+/*
+ *  A public method to get the OAuth token
+ *
+ *  @method getToken
+ *  @public
+ *  @return {string} token
+ */
+UsergridStorable.prototype.getToken = function () {
+    return this.get('token');
+};
+UsergridStorable.mixin	= function(destObject){
+    var props	= ['getStorage', 'setStorage', 'getStorageKey', 'get', 'set', 'getToken', 'setToken'];
+    for(var i = 0; i < props.length; i ++){
+        if(props[i] in destObject.prototype){
+            console.warn("overwriting '"+props[i]+"' on '"+destObject.name+"'.");
+            console.warn("the previous version can be found at '_"+props[i]+"' on '"+destObject.name+"'.");
+            destObject.prototype['_'+props[i]]=destObject.prototype[props[i]];
+        }
+        destObject.prototype[props[i]]	= UsergridStorable.prototype[props[i]];
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0a585ba/sdks/html5-javascript/usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/usergrid.js b/sdks/html5-javascript/usergrid.js
index b8debdf..ff83f6c 100644
--- a/sdks/html5-javascript/usergrid.js
+++ b/sdks/html5-javascript/usergrid.js
@@ -1,4 +1,40 @@
 /*! usergrid@0.0.0 2014-02-11 */
+var UsergridEventable = function() {
+    throw Error("'UsergridEventable' is not intended to be invoked directly");
+};
+
+UsergridEventable.prototype = {
+    bind: function(event, fn) {
+        this._events = this._events || {};
+        this._events[event] = this._events[event] || [];
+        this._events[event].push(fn);
+    },
+    unbind: function(event, fn) {
+        this._events = this._events || {};
+        if (event in this._events === false) return;
+        this._events[event].splice(this._events[event].indexOf(fn), 1);
+    },
+    trigger: function(event) {
+        this._events = this._events || {};
+        if (event in this._events === false) return;
+        for (var i = 0; i < this._events[event].length; i++) {
+            this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
+        }
+    }
+};
+
+UsergridEventable.mixin = function(destObject) {
+    var props = [ "bind", "unbind", "trigger" ];
+    for (var i = 0; i < props.length; i++) {
+        if (props[i] in destObject.prototype) {
+            console.warn("overwriting '" + props[i] + "' on '" + destObject.name + "'.");
+            console.warn("the previous version can be found at '_" + props[i] + "' on '"
+ destObject.name + "'.");
+            destObject.prototype["_" + props[i]] = destObject.prototype[props[i]];
+        }
+        destObject.prototype[props[i]] = UsergridEventable.prototype[props[i]];
+    }
+};
+
 //Logger
 (function() {
     var name = "Logger", global = this, overwrittenName = global[name], exports;
@@ -217,6 +253,102 @@
     return global[name];
 })();
 
+function UsergridStorable(storage, keyPrefix) {}
+
+UsergridStorable.prototype.setStorage = function(storage) {
+    if (!(storage instanceof Storage)) {
+        console.warn("parameter passed to 'setStorage' is not a browser Storage interface.
using sessionStorage");
+        storage = sessionStorage;
+    }
+    return this._storage = storage;
+};
+
+UsergridStorable.prototype.getStorage = function() {
+    if (!(this._storage instanceof Storage)) {
+        console.warn("parameter passed to 'setStorage' is not a browser Storage interface.
using sessionStorage");
+        this._storage = sessionStorage;
+    }
+    return this._storage;
+};
+
+UsergridStorable.prototype.getStorageKey = function(key) {
+    if (!this._keyPrefix) this._keyPrefix = "usergrid_js_sdk_";
+    return this._keyPrefix + key;
+};
+
+UsergridStorable.prototype.get = function(key) {
+    var value;
+    if (arguments.length > 1) {
+        key = [].slice.call(arguments).reduce(function(p, c, i, a) {
+            if (c instanceof Array) {
+                p = p.concat(c);
+            } else {
+                p.push(c);
+            }
+            return p;
+        }, []);
+    }
+    if (this._storage instanceof Storage) {
+        if (key instanceof Array) {
+            var self = this;
+            value = key.map(function(k) {
+                return self.get(k);
+            });
+        } else if ("undefined" !== typeof key) {
+            this[key] = JSON.parse(this.getStorage().getItem(this.getStorageKey(key)));
+            value = this[key];
+        }
+    }
+    return value;
+};
+
+UsergridStorable.prototype.set = function(key, value) {
+    if (this._storage instanceof Storage) {
+        if (value) {
+            this[key] = JSON.stringify(value);
+            this.getStorage().setItem(this.getStorageKey(key), this[key]);
+        } else {
+            delete this[key];
+            this.getStorage().removeItem(this.getStorageKey(key));
+        }
+    }
+};
+
+/*
+ *  A public method to store the OAuth token for later use - uses localstorage if available
+ *
+ *  @method setToken
+ *  @public
+ *  @params {string} token
+ *  @return none
+ */
+UsergridStorable.prototype.setToken = function(token) {
+    return this.set("token", token);
+};
+
+/*
+ *  A public method to get the OAuth token
+ *
+ *  @method getToken
+ *  @public
+ *  @return {string} token
+ */
+UsergridStorable.prototype.getToken = function() {
+    return this.get("token");
+};
+
+UsergridStorable.mixin = function(destObject) {
+    var props = [ "getStorage", "setStorage", "getStorageKey", "get", "set", "getToken",
"setToken" ];
+    for (var i = 0; i < props.length; i++) {
+        if (props[i] in destObject.prototype) {
+            console.warn("overwriting '" + props[i] + "' on '" + destObject.name + "'.");
+            console.warn("the previous version can be found at '_" + props[i] + "' on '"
+ destObject.name + "'.");
+            destObject.prototype["_" + props[i]] = destObject.prototype[props[i]];
+        }
+        destObject.prototype[props[i]] = UsergridStorable.prototype[props[i]];
+    }
+};
+
 /*
  *  This module is a collection of classes designed to make working with
  *  the Appigee App Services API as easy as possible.


Mime
View raw message