Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated class to a more sexy way of creating classes in js #22

Merged
merged 2 commits into from
Aug 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions client/scripts/storage/dataStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';


function LocalDataStorage() {

var currentIdKey = 'CurrentId';
Expand All @@ -8,22 +9,28 @@ function LocalDataStorage() {
localStorage.setItem(currentIdKey, 0);
}

this._getNextId = function() {
function getNextId () {
var currentId = localStorage.getItem(currentIdKey);
currentId ++;
localStorage.setItem(currentIdKey, currentId);
return currentId.toString();
}
}

LocalDataStorage.prototype.add = function(data) {
var dataId = this._getNextId();
localStorage.setItem(dataId, angular.toJson(data));
return dataId;
}

LocalDataStorage.prototype.get = function(dataId) {
var serializedData = localStorage.getItem(dataId);
return angular.fromJson(serializedData);
}
function add (data) {
var dataId = getNextId();
localStorage.setItem(dataId, angular.toJson(data));
return dataId;
}

function get(dataId) {
var serializedData = localStorage.getItem(dataId);
return angular.fromJson(serializedData);
}

return {
add : add,
get : get
}

}