Skip to content

Commit

Permalink
Correctly export addon files (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaulagiri authored Jun 18, 2018
1 parent 1ed3dc2 commit 01330b0
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 129 deletions.
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ automatically give you an input field, and will set `files` property when you
choose a file.

```js
import EmberUploader from 'ember-uploader';
import FileField from 'ember-uploader/components/file-field';
import Uploader from 'ember-uploader/uploaders/uploader';

export default EmberUploader.FileField.extend({
export default FileField.extend({
filesDidChange(files) {
const uploader = EmberUploader.Uploader.create({
const uploader = Uploader.create({
url: this.get('url')
});

Expand All @@ -44,7 +45,9 @@ By default, the request will be sent as `POST`. To override that, set `method` w
creating the object:

```js
const uploader = EmberUploader.Uploader.create({
import Uploader from 'ember-uploader/uploaders/uploader';

const uploader = Uploader.create({
url: '/upload',
method: 'PUT'
});
Expand All @@ -53,7 +56,9 @@ const uploader = EmberUploader.Uploader.create({
#### Change Namespace

```js
const uploader = EmberUploader.Uploader.create({
import Uploader from 'ember-uploader/uploaders/uploader';

const uploader = Uploader.create({
paramNamespace: 'post'
});

Expand All @@ -64,7 +69,9 @@ const uploader = EmberUploader.Uploader.create({
By default parameter will be `file`

```js
const upload = EmberUploader.Uploader.create({
import Uploader from 'ember-uploader/uploaders/uploader';

const upload = Uploader.create({
paramName: 'upload'
});

Expand Down Expand Up @@ -109,14 +116,15 @@ uploader.upload(file).then(data => {

#### Multiple files
```js
import EmberUploader from 'ember-uploader';
import FileField from 'ember-uploader/components/file-field';
import Uploader from 'ember-uploader/uploaders/uploader';

export default EmberUploader.FileField.extend({
export default FileField.extend({
multiple: true,
url: 'http://example.com/upload',

filesDidChange(files) {
const uploader = EmberUploader.Uploader.create({
const uploader = Uploader.create({
url: this.get('url')
});

Expand All @@ -135,9 +143,9 @@ settings required by Ember Uploader. Here we modify the headers sent with
the request.

```js
import EmberUploader from 'ember-uploader';
import Uploader from 'ember-uploader/uploaders/uploader';

export default EmberUploader.Uploader.extend({
export default Uploader.extend({
ajaxSettings: {
headers: {
'X-Application-Name': 'Uploader Test'
Expand All @@ -156,13 +164,14 @@ able to make an authenticated request to S3. This step is required to avoid
saving secret token on your client.

```js
import EmberUploader from 'ember-uploader';
import FileField from 'ember-uploader/components/file-field';
import Uploader from 'ember-uploader/uploaders/uploader';

export default EmberUploader.FileField.extend({
export default FileField.extend({
signingUrl: '',

filesDidChange(files) {
const uploader = EmberUploader.S3Uploader.create({
const uploader = S3Uploader.create({
signingUrl: this.get('signingUrl')
});

Expand Down
2 changes: 0 additions & 2 deletions addon/components.js

This file was deleted.

8 changes: 5 additions & 3 deletions addon/components/file-field.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ember from 'ember';
import { isEmpty } from '@ember/utils';
import Evented from '@ember/object/evented';
import Component from '@ember/component';

export default Ember.Component.extend(Ember.Evented, {
export default Component.extend(Evented, {
tagName: 'input',
type: 'file',
attributeBindings: [
Expand All @@ -16,7 +18,7 @@ export default Ember.Component.extend(Ember.Evented, {
multiple: false,
change (event) {
const input = event.target;
if (!Ember.isEmpty(input.files)) {
if (!isEmpty(input.files)) {
this.trigger('filesDidChange', input.files);
}
}
Expand Down
29 changes: 0 additions & 29 deletions addon/core.js

This file was deleted.

21 changes: 0 additions & 21 deletions addon/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions addon/uploaders.js

This file was deleted.

20 changes: 9 additions & 11 deletions addon/uploaders/s3.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Ember from 'ember';
import Uploader from 'ember-uploader/uploaders/base';

const {
get,
set,
run
} = Ember;
import $ from 'jquery';
import { Promise } from 'rsvp';
import { set, get } from '@ember/object';
import { run } from '@ember/runloop';
import Uploader from 'ember-uploader/uploaders/uploader';
import { assign } from '@ember/polyfills';

export default Uploader.extend({
/**
Expand Down Expand Up @@ -75,7 +73,7 @@ export default Uploader.extend({
extra.type = file.type;
extra.size = file.size;

const settings = Ember.assign(
const settings = assign(
{},
{
contentType: 'application/json',
Expand All @@ -89,7 +87,7 @@ export default Uploader.extend({

set(this, 'isSigning', true);

return new Ember.RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
settings.success = (json) => {
run(null, resolve, this.didSign(json));
};
Expand All @@ -98,7 +96,7 @@ export default Uploader.extend({
run(null, reject, this.didErrorOnSign(jqXHR, responseText, errorThrown));
};

Ember.$.ajax(settings);
$.ajax(settings);
});
},

Expand Down
25 changes: 12 additions & 13 deletions addon/uploaders/base.js → addon/uploaders/uploader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Ember from 'ember';

const {
get,
set,
run
} = Ember;

export default Ember.Object.extend(Ember.Evented, {
import { Promise } from 'rsvp';
import $ from 'jquery';
import { assign } from '@ember/polyfills';
import Evented from '@ember/object/evented';
import EmberObject, { set, get } from '@ember/object';
import { run } from '@ember/runloop';

export default EmberObject.extend(Evented, {
/**
* Target url to upload to
*
Expand Down Expand Up @@ -179,13 +178,13 @@ export default Ember.Object.extend(Ember.Evented, {
* object
*/
ajax (url, data = {}, method = this.method) {
const ajaxSettings = Ember.assign(
const ajaxSettings = assign(
{},
{
contentType: false,
processData: false,
xhr: () => {
const xhr = Ember.$.ajaxSettings.xhr();
const xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = (event) => {
this.didProgress(event);
};
Expand All @@ -210,7 +209,7 @@ export default Ember.Object.extend(Ember.Evented, {
* @return {object} Returns a Ember.RSVP.Promise wrapping the ajax request
*/
ajaxPromise (settings) {
return new Ember.RSVP.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
settings.success = (data) => {
run(null, resolve, this.didUpload(data));
};
Expand All @@ -219,7 +218,7 @@ export default Ember.Object.extend(Ember.Evented, {
run(null, reject, this.didError(jqXHR, responseText, errorThrown));
};

Ember.$.ajax(settings);
$.ajax(settings);
});
}
});
3 changes: 1 addition & 2 deletions app/components/file-field.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import FileField from 'ember-uploader/components/file-field';
export default FileField;
export { default } from 'ember-uploader/components/file-field';
1 change: 1 addition & 0 deletions app/uploaders/s3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-uploader/uploaders/s3';
1 change: 1 addition & 0 deletions app/uploaders/uploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-uploader/uploaders/uploader';
6 changes: 0 additions & 6 deletions generators/license.js

This file was deleted.

8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
'use strict';

module.exports = {
name: 'ember-uploader',
treeForAddon: function(dir) {
let version = require('./lib/version');
let merge = require('broccoli-merge-trees');

return this._super.treeForAddon.call(this, merge([version(), dir]));
}
name: 'ember-uploader'
};
8 changes: 0 additions & 8 deletions lib/version.js

This file was deleted.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"node": "^4.5 || 6.* || >= 7.*"
},
"dependencies": {
"broccoli-file-creator": "^1.0.1",
"broccoli-merge-trees": "^1.0.0",
"ember-cli-babel": "^6.6.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module } from 'qunit';
import { setupTest } from 'ember-qunit';
import { computed } from '@ember/object';
import $ from 'jquery';
import { S3Uploader } from 'ember-uploader/uploaders';
import S3Uploader from 'ember-uploader/uploaders/s3';
import test from 'ember-sinon-qunit/test-support/test';
import { startMirage } from 'dummy/initializers/ember-cli-mirage';

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/uploader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { module } from 'qunit';
import { setupTest } from 'ember-qunit';
import { computed } from '@ember/object';
import $ from 'jquery';
import { Uploader } from 'ember-uploader/uploaders';
import Uploader from 'ember-uploader/uploaders/uploader';
import test from 'ember-sinon-qunit/test-support/test';
import TestableFormData from '../helpers/form-data';
import { startMirage } from 'dummy/initializers/ember-cli-mirage';

let file;

module("EmberUploader.Uploader", function(hooks) {
module('EmberUploader.Uploader', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ broccoli-debug@^0.6.1, broccoli-debug@^0.6.3, broccoli-debug@^0.6.4:
symlink-or-copy "^1.1.8"
tree-sync "^1.2.2"

broccoli-file-creator@^1.0.1, broccoli-file-creator@^1.1.1:
broccoli-file-creator@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.2.0.tgz#27f1b25b1b00e7bb7bf3d5d7abed5f4d5388df4d"
dependencies:
Expand Down

0 comments on commit 01330b0

Please sign in to comment.