Skip to content

Commit

Permalink
data delegate updates
Browse files Browse the repository at this point in the history
  • Loading branch information
robrobbins committed Mar 26, 2013
1 parent 1b2c182 commit 098c14b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
52 changes: 38 additions & 14 deletions build/debug/sudo-x.js
Expand Up @@ -1021,7 +1021,7 @@ sudo.Navigator.prototype.setData = function setData() {
// Gather the necessary information about the current environment and // Gather the necessary information about the current environment and
// bind to either (push|pop)state or hashchange. // bind to either (push|pop)state or hashchange.
// Also, if given an imcorrect URL for the current environment (hashchange // Also, if given an imcorrect URL for the current environment (hashchange
// vs pushState) normalize it and set accordingly. // vs pushState) normalize it and set accordingly (or don't).
// //
// `returns` {object} `this` // `returns` {object} `this`
sudo.Navigator.prototype.start = function start() { sudo.Navigator.prototype.start = function start() {
Expand All @@ -1043,26 +1043,31 @@ sudo.Navigator.prototype.start = function start() {
} else if (this.isHashChange) { } else if (this.isHashChange) {
$(window).on('hashchange', this.handleChange.bind(this)); $(window).on('hashchange', this.handleChange.bind(this));
} else return; } else return;
// Does the current URL need to changed? (hashchange vs popstate)
atRoot = window.location.pathname.replace(/[^\/]$/, '$&/') === this.data['root']; atRoot = window.location.pathname.replace(/[^\/]$/, '$&/') === this.data['root'];
// somehow a pushstate URL got here (and here is hashchange) // somehow a URL got here not in my 'format', unless explicitly told not too, correct this
if(this.isHashChange && !atRoot) { if(!this.data.stay) {
window.location.replace(this.data['root'] + window.location.search + '#' + if(this.isHashChange && !atRoot) {
this.data.fragment); window.location.replace(this.data['root'] + window.location.search + '#' +
// return early as browser will redirect this.data.fragment);
return true; // return early as browser will redirect
// the converse of the above return true;
} else if(this.isPushState && atRoot && window.location.hash) { // the converse of the above
tmp = this.getHash().replace(this.leadingStripper, ''); } else if(this.isPushState && atRoot && window.location.hash) {
window.history.replaceState({}, document.title, this.data['root'] + tmp = this.getHash().replace(this.leadingStripper, '');
tmp + window.location.search); window.history.replaceState({}, document.title, this.data['root'] +
tmp + window.location.search);
}
} }
// TODO provide option to `go` from inital `start` state? // TODO provide option to `go` from inital `start` state?
return this; return this;
}; };
// Is a passed in fragment different from the currently set one? // ###urlChanged
// Is a passed in fragment different from the one currently set at `this.get('fragment')`?
// If so set the fragment to the passed fragment passed in (as well as any 'query' data), else
// simply return false
// //
// `param` {String} `fragment` // `param` {String} `fragment`
// `returns` {bool}
sudo.Navigator.prototype.urlChanged = function urlChanged(fragment) { sudo.Navigator.prototype.urlChanged = function urlChanged(fragment) {
var current = this.getFragment(fragment); var current = this.getFragment(fragment);
// nothing has changed // nothing has changed
Expand Down Expand Up @@ -1728,6 +1733,16 @@ sudo.delegates.Data = function(data) {
}; };
// inherits from Model // inherits from Model
sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype); sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype);
// ###addFilter
// Place an entry into this object's hash of filters
//
// `param` {string} `key`
// `param` {string} `val`
// `returns` {object} this
sudo.delegates.Data.prototype.addFilter = function addFilter(key, val) {
this.data.filters[key] = val;
return this;
};
// ###filter // ###filter
// iterates over a given object literal and returns a value (if present) // iterates over a given object literal and returns a value (if present)
// located at a given key or path // located at a given key or path
Expand All @@ -1752,6 +1767,15 @@ sudo.delegates.Data.prototype.filter = function(obj) {
} }
} }
}; };
// ###removeFilter
// Remove an entry from this object's hash of filters
//
// `param` {string} `key`
// `returns` {object} this
sudo.delegates.Data.prototype.removeFilter = function removeFilter(key) {
delete this.data.filters[key];
return this;
};
// `private` // `private`
sudo.delegates.Data.prototype.role = 'data'; sudo.delegates.Data.prototype.role = 'data';


Expand Down
19 changes: 19 additions & 0 deletions extras/delegates/data/data.js
Expand Up @@ -13,6 +13,16 @@ sudo.delegates.Data = function(data) {
}; };
// inherits from Model // inherits from Model
sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype); sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype);
// ###addFilter
// Place an entry into this object's hash of filters
//
// `param` {string} `key`
// `param` {string} `val`
// `returns` {object} this
sudo.delegates.Data.prototype.addFilter = function addFilter(key, val) {
this.data.filters[key] = val;
return this;
};
// ###filter // ###filter
// iterates over a given object literal and returns a value (if present) // iterates over a given object literal and returns a value (if present)
// located at a given key or path // located at a given key or path
Expand All @@ -37,6 +47,15 @@ sudo.delegates.Data.prototype.filter = function(obj) {
} }
} }
}; };
// ###removeFilter
// Remove an entry from this object's hash of filters
//
// `param` {string} `key`
// `returns` {object} this
sudo.delegates.Data.prototype.removeFilter = function removeFilter(key) {
delete this.data.filters[key];
return this;
};
// `private` // `private`
sudo.delegates.Data.prototype.role = 'data'; sudo.delegates.Data.prototype.role = 'data';


0 comments on commit 098c14b

Please sign in to comment.