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

Alternative adapters? #132

Open
cbetta opened this issue Mar 12, 2015 · 3 comments
Open

Alternative adapters? #132

cbetta opened this issue Mar 12, 2015 · 3 comments
Labels

Comments

@cbetta
Copy link

cbetta commented Mar 12, 2015

Is there a list of alternative adapters anywhere? MotionModel::ArrayModelAdapter is a nice starting point but a bit useless beyond initial experiments.

@sxross
Copy link
Owner

sxross commented Mar 12, 2015

There is the SQL branch, which uses FMDB as a backing store. I've not used it because my needs are more for a backing store with some data manipulation capability instead of a major database search/sort kind of thing. I've also done some strawman integrations with Meteor DDP and with Firebase, but the code is preliminary. What is the use case that makes ArrayModelAdapter insufficient to the task?

@cbetta
Copy link
Author

cbetta commented Mar 12, 2015

Well I can load my data and then display it, but when the app gets killed in the background I want to have some data ready cached.

@sxross
Copy link
Owner

sxross commented Mar 12, 2015

I simply set an observer on the MotionModelDataDidChange notification and persist the data store. This is not so expensive that the user ever notices the delay in my experience. Here's a snippet of code I keep in AppDelegate:

  ################ Persistence Is Handled in Asynchronous Queue #################
  def observe_change
    @model_change_observer = App.notification_center.observe MotionModelDataDidChangeNotification do |notification|
      queue = Dispatch::Queue.concurrent('com.calicowebdev.whos_here.task')
      queue.async{
        begin
          save_one(notification.object.class)
        rescue MotionModel::PersistFileError => ex
          App.notification_center.post MotionModelPersistFileError, Time.now,
                                            {:status => 'failure', :exception => ex.message}
        end
        file_sizes
      }
    end
  end

I have a slightly more elegant version that creates a block that observes a given model, but this should give you an idea how I set it up. It will persist changes across settings every time you save/update/delete a collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants