Skip to content

Instantly share code, notes, and snippets.

@richchurcher
Created June 11, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richchurcher/63a3b67715c7e42c22c1 to your computer and use it in GitHub Desktop.
Save richchurcher/63a3b67715c7e42c22c1 to your computer and use it in GitHub Desktop.
function Board() {}
Board.prototype.save = function () {
ApiFacade.putBoard(this, function (payload) {
// TODO: use response here in some fashion? Error handling?
console.log("Payload returning from save(): ", payload);
});
}
Board.prototype.load = function () {
ApiFacade.retrieveBoard(this.loadCallback.bind(this));
}
Board.prototype.loadCallback = function (payload) {
if (payload) {
console.log("Payload returning from load(): ", payload);
// Add methods to models
$.extend(this, payload);
if (this.bubbles) {
for (var i = 0; i < this.bubbles.length; i++) {
var bubble = new Bubble();
$.extend(this.bubbles[i], bubble);
}
} else {
this.bubbles = [];
}
if (this.connections) {
for (var i = 0; i < this.connections.length; i++) {
var connection = new Connection();
$.extend(this.connections[i], connection);
}
} else {
this.connections = [];
}
this.render();
// TODO: remove once empty!
eventHandlers();
} else {
// TODO: handle error. Retry?
console.log("Empty payload in board.load()");
}
}
Board.prototype.render = function () {
if (this.bubbles) {
for (var i = 0; i < this.bubbles.length; i++) {
this.bubbles[i].render();
}
}
if (this.connections) {
for (var i = 0; i < this.connections.length; i++) {
this.connections[i].render(mySVG);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment