Skip to content

Instantly share code, notes, and snippets.

@akatov
Last active June 5, 2017 02:14
Show Gist options
  • Save akatov/012a3ed3541126e5997438b2e1609eab to your computer and use it in GitHub Desktop.
Save akatov/012a3ed3541126e5997438b2e1609eab to your computer and use it in GitHub Desktop.
Ember Pouch Experiments
import { Adapter } from 'ember-pouch';
import service from 'ember-service/inject';
import { wrap } from 'ember-co';
export default Adapter.extend({
unloadedDocumentChanged: wrap(function*(obj) {
const store = get(this, 'store');
const type = store.modelFor(obj.type);
this._init(store, type); // make sure the type is in relational-pouch's schema
const recordTypeName = this.getRecordTypeName(type);
const db = get(this, 'db');
const docs = yield db.rel.find(recordTypeName, obj.id);
// apparently sometimes we're outside a runloop here, especially in testing...
run(store, 'pushPayload', docs);
}),
});
import Ember from 'ember';
import DS from 'ember-data';
import co from 'ember-co';
export default Ember.Controller.extend({
appName: 'hello',
pouch: Ember.inject.service(),
db: Ember.computed.alias('pouch.db'),
});
import Model from "ember-pouch/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
});
import Ember from 'ember';
import PouchDB from 'pouchdb';
export default Ember.Service.extend({
db: Ember.computed(function () {
return new PouchDB('testing');
})
});
<h1>Welcome to {{appName.name}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
the database is {{db}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"babel-polyfill": "https://cdn.rawgit.com/nicksrandall/babel-polyfill/master/browser-polyfill.js",
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-pouch": "4.2.5",
"ember-co": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment