Closed weepy closed 12 years ago
+1 as an o_O.memorystore.js plugin, -1 to being built into o_O.js directly
added a sketch for how this might work
here's a sketch - what do you think ?
o_O.memoryStore = function() {
this._id = 0
this.objects = {}
this.types = {}
}
var proto = o_O.memoryStore.prototype
proto.uniqueId = function() {
return ++this._id
}
proto.find = function(id) {
return this.objects[i]
}
proto.add = function(object) {
var id = object.id
if(id == null || !this.find(id) ) {
object.id = id || this.uniqueId()
this.objects[id] = object
}
}
proto.remove = function(o) {
delete this.objects[o.id]
}
// merge in some methods to o_O.model
o_O.model.protoype.store = new o_O.memoryStore()
o_O.model.protoype.save = function() {
this.store.add(this)
}
// o_O.model already acts as a factory
// doesn't makes sense to move this to o_O.store
o_O.model.types = {...}
o_O.model.create = function(){ ... } // perhaps better to call something like `instantiate` - although a bit long
// how do deal with loading id's and so should update the _id so that the unique id
// whenever adding an object - check to see if object.id >= this._id ?
Hmm thinking about it - I see your point I think. What is the use of a memory store ? -- as we already have the objects ^_^
ok to reserve id, and type and keep them as normal properties rather than o_O.properties ?
why would we not want type and id to be o_O.properties?
records don't change their id's or types ?
That is true, but why special-case it?
a fair point . perhaps it's silly
closing
It might be worth removing the logic in the model that deals with .id and .type , and moving them to a store.
It would be a memory store by default, but easy enough to plugin different stores.
.save would probably assign an id