Created
September 23, 2015 20:51
-
-
Save soberstadt/0abae48a4b1e9b374e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('missionhub') | |
.factory('personCache', function() { | |
// set up variables and constants | |
var cachedPeople = {}; | |
// define methods | |
// if you give person() a person object, it will cache it. | |
// if you give it an id, it will return a person object if it has it. | |
function person(newValue) { | |
if (newValue.id) { | |
cachedPeople[newValue.id] = cachedPeople[newValue.id] || {} | |
angular.extend(cachedPeople[newValue.id], newValue); | |
return true; | |
} | |
return cachedPeople[newValue]; | |
} | |
// return interface | |
return { | |
person: person | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment