Skip to content

Commit

Permalink
[#31] Remove jQuery
Browse files Browse the repository at this point in the history
* [x] Strip jQuery in ember-cli-build.js
* [x] Try to ember-data to use ember-fetch instead of $.ajax
* [x] app/adapters/application.js added the authorization: <bearer token> header to outgoing requests
* [x] ma-create-media guards against disabled button
* [x] updated dependencies
  • Loading branch information
0xadada committed Feb 18, 2018
1 parent 2048f9c commit 3debfae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
22 changes: 19 additions & 3 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { get } from '@ember/object';
import { inject as service } from '@ember/service';
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import AdapterFetchMixin from 'ember-fetch/mixins/adapter-fetch';
import config from 'mir/config/environment';

export default JSONAPIAdapter.extend(DataAdapterMixin, {
export default JSONAPIAdapter.extend(AdapterFetchMixin, {
session: service(),

/* Ember */
host: config.DS.host,
namespace: config.DS.namespace,

/* DataAdapterMixin */
authorizer: 'authorizer:oauth2'
authorizer: 'authorizer:oauth2',

/* mir */
ajaxOptions() {
const authorizer = get(this, 'authorizer');
const options = this._super(...arguments) || {};
options.headers = options.headers || {};
options.headers['Content-Type'] = 'application/vnd.api+json';
get(this, 'session').authorize(authorizer, (headerName, headerValue) => {
options.headers[headerName] = headerValue;
});
return options;
}
});
5 changes: 4 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const VERSION = GETENVJSON().version;

module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
fingerprint: {
extensions: ['css', 'gif', 'js', 'jpg', 'png', 'map', 'svg']
},
Expand All @@ -30,6 +29,10 @@ module.exports = function(defaults) {

svgJar: {
sourceDirs: ['public/images']
},

vendorFiles: {
'jquery.js': null // removes jQuery from build
}
});

Expand Down
2 changes: 2 additions & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ export default function() {
this.del('/medias/:id', (schema, request) => {
let media = schema.medias.find(request.params.id);
media.destroy();
// TODO: Hacks
return { data: null }; // i shouldn't have to return anything here
});
}
1 change: 0 additions & 1 deletion tests/acceptance/media/new-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module('Application | media/new', function(hooks) {
});

test('can add and delete valid media', async function(assert) {
server.logging = true;
assert.expect(3);
// create an OAuth token w/ ember-cli-mirage
await visit('/media/new');
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2341,9 +2341,9 @@ columnify@~1.5.4:
strip-ansi "^3.0.0"
wcwidth "^1.0.0"

combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818"
dependencies:
delayed-stream "~1.0.0"

Expand Down Expand Up @@ -4426,11 +4426,11 @@ form-data@~2.1.1:
mime-types "^2.1.12"

form-data@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf"
version "2.3.2"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.5"
combined-stream "1.0.6"
mime-types "^2.1.12"

forwarded@~0.1.2:
Expand Down Expand Up @@ -8922,8 +8922,8 @@ source-map@~0.2.0:
amdefine ">=0.0.4"

sourcemap-validator@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.0.6.tgz#abd2f1ecdae6a3c46c2c96c5f256705b2147c9c0"
version "1.0.7"
resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.0.7.tgz#d76aaadbe2c6ec269293b5f212100fad91eef260"
dependencies:
jsesc "~0.3.x"
lodash.foreach "~2.3.x"
Expand Down

0 comments on commit 3debfae

Please sign in to comment.