No persistent data on Firefox OS using ember-localforage-adapter - ember.js

I've got an issue with using this adapter.
I'm a noob in Ember, so it might be (and probably is) my error...
Ember 1.13.8
Ember Localforage Adapter 1.13.1
Adding an entry is fine - adapter is called.
Adapter isn't called when the application is started.
Data is missing when an app is reloaded.
https://github.com/zalun/stereophoto/tree/master/ember-stereophoto

You are using peekAll to retrieve all the models in your stereos/index route but in the adapter of localforage peekAll is not overwritten (which means that its behaviour hasn't been changed from its original one in ember-data). You should use findAllinstead.

Related

Elesticsearch and Emberjs

I'm trying to wire EmberJS with ElasticSearch. So far, I've read most of the Ember documentation, and found out this adapter for ElasticSearch.
The problem is I can't figure out how to use it (i.e. configure it so that when I call store.save(), my model is sent to ES.
What I have ATM is a newly created project with Ember generator (ember new ), and a generated controller, router, model, etc. My problem is that the Ember document explains how to customise adapters, but not how to use them (or I missed that part). The ES adapter's documentation says :
var App = Em.Application.create();
App.store = DS.Store.create({
revision: 4,
adapter: DS.ElasticSearchAdapter.create({url: 'http://localhost:9200'})
});
which implies to create a Store, whereas I can only see ways to extend it in the Ember documentation. Furthermore, I already have a Store in my application.
So the questions are:
do I need to override the store creation to replace it with the ES one (and where to do that) OR
do I need to extend the existing one, and in this case, how should I do that ?
Also, when it says:
First, load the ember-data/lib/adapters/elasticsearch_adapter.js file
in your application.
where and how that should be done ?
On your first questions/s
do I need to override the store creation to replace it with the ES one
(and where to do that) OR do I need to extend the existing one, and in
this case, how should I do that ?
You're onto the right track in the second part, you will need extend the existing one, but not the store, the adapter in this case.
So if you're using ember-cli, which according to this:
What I have ATM is a newly created project with Ember generator (ember
new )
It seems that you are and so you'll application folder structure should be like this:
app ->
adapters(you need to generate/create this)
components
controllers
models
routes
serializers
services
styles
templates
And now we can answer:
how should I do that ?
If you do not have the adapters folder yet, which you probably don't, just run ember generate adapter application or create a folder adapters, and a file application.js for that folder.
And that then finally leads us to a part of your last question.
load the ember-data/lib/adapters/elasticsearch_adapter.js file in your
application. where and how that should be done ?
import ElasticSearchAdapter from 'ember-data/lib/adapters/elasticsearch_adapter'
export default ElasticSearchAdapter.extend({
})
Now the possible bad news, that adapter is likely very outdated, as it the repository's last commit was 27 Dec 2012.

How to unload a record in Ember 2.3.0?

I am upgrading an Ember 1.13.0 application to Ember 2.3.0 and I'm facing a little issue where I am unable to unload a record from the Data Store without causing Ember to make a HTTP request. I do not want to delete the record in the server. I simply want to remove it from Ember Data Store.
I was using the following Ember DS.Store API: http://emberjs.com/api/data/classes/DS.Store.html#method_unloadRecord in Ember 1.13.0 and it worked fine. Sample:
this.store.find('post', 1).then(function(post) {
this.store.unloadRecord(post);
});
After upgrading to 2.3.0, when I monitor the network tab in Chrome, Ember is making a GET request to find the record and then unload it. Because it fails to find (our server does not have an API to match this call), it doesn't unload the record and the changes don't appear in the UI.
I tried to fix this by instead doing something like:
this.store.peekRecord('posts', 1).then(function(post) {
this.store.unloadRecord(post);
});
but this doesn't seem to work. What is the right way to unload a record from Ember Data without making HTTP calls? Thanks.
Ember data automatically reloads records to keep them in sync with server. So findRecord() resolves immediately, but in background it makes request to the server and update values when it returns. This behavior was changed in ember-data 1.13.0 and is described in toc_new-adapter-hooks-for-better-caching.
The issue with peekRecord is that peek* methods just asks store and thus don't need to return promise. Therefore your code should look like this:
const store = this.get('store');
const post = store.peekRecord('posts', 1);
if (post) {
store.unloadRecord(post);
}

Ember Route now is singleton ? Needs confirmation

I'm using Ember 1.13.3, and somehow I noticed now that Route is also singleton (?), just like controller.
I was checking it because I notice a bug in my app since I upgraded to 1.13.3, and to confirm my suspicion I added console.log in the init method..., and saw that init method is called only once for the route (I switched to another route and wend back).
Is it new (in Ember 1.13, and onward) ?
I need the confirmation if route is really singleton now, in order to rule out the possibility that this behavior I was observing was due to certain (mis)programming (my code).
Thanks,
Raka

Force Ember-Data to reload belongsTo/hasMany relationships on find

How can I tell ember-data to also reload the related entities?
When I run the the following for the second time it will nicely reload the posts, but will not reload the belongs/hasMany relationships (Which were loaded on the first time).
model: function() {
return this.store.findAll('posts',{reload:true});
},
I know there are many scenarios where this is wanted, but in my scenario the related entities can have changed.
Implement a socket.io service notifiying me of changes isn't an option as I don't have enough control of the server.
Note: I'm on Ember 2.0.0 and Ember-Data Canary
There seems to be no inbuilt solution, only workarounds.
e.g. call
store.unloadAll('typeOfRelationship');
before calling findAll

Ember ApplicationRoute with other Routes

I have a basic ember question here. I'm looking to set up an ember ApplicationRoute that gets loaded immediately, and have all other routes extend from this application route. I would like the data that the ApplicationRoute loads to be loaded on every page transition. Is this possible? FYI I'm also using ember-data and rails as an API.
Thanks!
If you want a real time data pushed from a server you should try extending your ApplicationAdapter to handle data from websocket connection and push in to the store object. A nice example of parsing model data from websocket connection may be found in API docs http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_extract