An Ember service for managing a Horizon connection, and an adapter to request data from that connection.
ember install ember-cli-horizon
config/environment.js
var ENV = {
// ...
horizon: {
host: 'localhost:8181'
// Any other config options: http://horizon.io/api/horizon/#constructor
}
// ...
};
app/foo/component.js
import Ember from 'ember';
import { HorizonConnectionService } from 'ember-cli-horizon/services/horizon-connection';
export default Ember.Component.extend({
horizonConnection: Ember.inject.service(),
init() {
this._super(...arguments);
const horizonConnection = this.get('horizonConnection');
if (horizonConnection.isReady) {
someMethodThatUsesHorizon(horizonConnection.hz);
} else {
horizonConnection.connect().then(hz => {
if (this.isDestroying || this.isDestroyed) {
return;
}
someMethodThatUsesHorizon(hz);
}); // Should also catch a connection error here and handle it
}
}
})
app/foo/adapter.js
export { default } from 'ember-cli-horizon/adapters/horizon';
Now just use the foo model like any other. No other work required. Note that this naively maps EmberData model name to Horizon collection name. I haven't figured out a good way to alter this mapping without making any silly couplings that I'd like to avoid, let me know if you have any ideas.
- This is currently a work in progress.
- The fetch adapter and connection should work just fine for basic use cases.
- I would appreciate any beta testing and feedback.
- There is a streaming adapter in progress, but it is not available yet.
- There are no tests.
- I still need to figure out just how I'm going to set up automated testing against a real horizon instance.
- I'm brainstorming on solutions, I promise.