class Volt::Persistors::LocalStore
Backs a collection in the local store
Public Instance Methods
added(model, index)
click to toggle source
Called when a model is added to the collection
# File lib/volt/models/persistors/local_store.rb, line 10 def added(model, index) root_model.persistor.save_all end
changed(attribute_name)
click to toggle source
Callled when an item is changed (or removed)
# File lib/volt/models/persistors/local_store.rb, line 33 def changed(attribute_name) root_model.persistor.save_all true end
loaded(initial_state = nil)
click to toggle source
Calls superclass method
Volt::Persistors::Base#loaded
# File lib/volt/models/persistors/local_store.rb, line 14 def loaded(initial_state = nil) super # When the main model is first loaded, we pull in the data from the # store if it exists if @model.path == [] json_data = LocalStorage['volt-store'] if json_data root_attributes = EJSON.parse(json_data) @loading_data = true root_attributes.each_pair do |key, value| @model.send(:"_#{key}=", value) end @loading_data = nil end end end
save_all()
click to toggle source
Called on the root
# File lib/volt/models/persistors/local_store.rb, line 40 def save_all return if @loading_data json_data = EJSON.stringify(@model.to_h) LocalStorage['volt-store'] = json_data end