ember-git-data
v0.1.5
Published
The default blueprint for ember-cli addons.
Downloads
2
Readme
Ember Git Data
Minimal wrapper for git-data.js. For API info, please see git-data.js's docs.
Install
$ ember install ember-git-data
Use
Extend the Ember.Service that comes with this addon, and provide your GitHub access token:
// app/services/github.js
import Ember from 'ember'
import GitHub from 'ember-git-data/services/github'
const {
inject: { service },
computed: { readOnly },
} = Ember
// don't forget to extend!
export default GitHub.extend({
session: service(),
token: readOnly('session.accessToken'),
})
You can now create as many Repo objects as you wish. Often, you will want to return the Repo object as part of an Ember.Route's model hook:
// app/routes/index.js
import Ember from 'ember'
const {
inject: { service },
get,
} = Ember
export default Ember.Route.extend({
github: service(),
async model() {
const g = get(this, 'github')
const repo = g.repo({
owner: 'nucleartide',
repo: 'ember-git-data',
branch: 'master',
})
try {
const packageJson = await repo.readFile('package.json')
return { packageJson, repo }
} catch (err) {
// ...
}
},
actions: {
doStuffWithRepo() {
const { repo } = this.modelFor(this.routeName)
// ...
}
}
})
The Repo object is now cached while a user is visiting the route, and you can perform any actions you wish.
Async/Await Note
The async/await syntax works with apps that opt in by setting the following in their ember-cli-build.js
:
babel: {
includePolyfill: true
}
Rationale
Why not use Ember Data?
Ember Data is great, and git-data.js could have easily been implemented as Ember Data models/adapters/serializers. I wanted to decouple git-data.js from Ember Data though, and make it usable in non-Ember environments.
Why not extend ember-data-github?
git-data.js focuses solely on GitHub's Git Data API. ember-data-github seems to have a broader focus.