Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ember-decorators dependency #20

Merged
merged 3 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions addon/components/phone-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import Component from '@ember/component'
import { assert } from '@ember/debug'
import { attribute, tagName } from '@ember-decorators/component'

const { intlTelInput } = window

Expand All @@ -23,13 +22,15 @@ const PHONE_NUMBER_FORMAT = 'E164' // https://en.wikipedia.org/wiki/E.164
@class PhoneInput
@public
*/
@tagName('input')
export default class PhoneInput extends Component {
@attribute
type = 'tel'

export default Component.extend({
tagName: 'input',

attributeBindings: ['type'],
type: 'tel',

init() {
super.init(...arguments)
this._super(...arguments)

this._iti = this._iti || null

Expand Down Expand Up @@ -109,7 +110,7 @@ export default class PhoneInput extends Component {
"`autoPlaceholder` possible values are 'polite', 'aggressive' and 'off'",
validAutoPlaceholer
)
}
},

input() {
const format = intlTelInputUtils.numberFormat[PHONE_NUMBER_FORMAT]
Expand All @@ -119,10 +120,10 @@ export default class PhoneInput extends Component {
this.update(internationalPhoneNumber, meta)

return true
}
},

didInsertElement() {
super.didInsertElement(...arguments)
this._super(...arguments)

const {
autoPlaceholder,
Expand Down Expand Up @@ -152,7 +153,7 @@ export default class PhoneInput extends Component {
}

this.update(number, this._metaData(_iti))
}
},

// this is a trick to format the number on user input
didRender() {
Expand All @@ -169,13 +170,13 @@ export default class PhoneInput extends Component {
if (this.number) {
this._iti.setNumber(this.number)
}
}
},

willDestroyElement() {
this._iti.destroy()

super.willDestroyElement(...arguments)
}
this._super(...arguments)
},

_metaData(iti) {
const extension = iti.getExtension()
Expand All @@ -188,4 +189,4 @@ export default class PhoneInput extends Component {
isValidNumber
}
}
}
})
19 changes: 10 additions & 9 deletions addon/services/phone-input.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Service from '@ember/service'
import { getOwner } from '@ember/application'
import loadScript from 'ember-phone-input/utils/load-script'
import RSVP from 'rsvp'

export default class PhoneInputService extends Service {
didLoad = this.didLoad || false
export default Service.extend({
didLoad: false,

init() {
super.init(...arguments)
this._super(...arguments)

const config = getOwner(this).resolveRegistration('config:environment')
const { lazyLoad, hasPrepend } = config.phoneInput
Expand All @@ -18,32 +19,32 @@ export default class PhoneInputService extends Service {
// that is to say at the app boot
this.load()
}
}
},

load() {
const doLoadScript1 = this.didLoad
? Promise.resolve()
? RSVP.resolve()
: loadScript(
this._loadUrl('assets/ember-phone-input/scripts/intlTelInput.min.js')
)

const doLoadScript2 = this.didLoad
? Promise.resolve()
? RSVP.resolve()
: loadScript(this._loadUrl('assets/ember-phone-input/scripts/utils.js'))

return Promise.all([doLoadScript1, doLoadScript2]).then(() => {
return RSVP.all([doLoadScript1, doLoadScript2]).then(() => {
if (this.isDestroyed) {
return
}

this.set('didLoad', true)
})
}
},

_loadUrl(url) {
const { rootURL } = getOwner(this).resolveRegistration('config:environment')
const prependUrl = this.hasPrepend ? '' : rootURL

return `${prependUrl}${url}`
}
}
})
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@
"test:all": "ember try:each"
},
"dependencies": {
"@ember-decorators/babel-transforms": "^3.1.0",
"babel-eslint": "^10.0.1",
"ember-cli-babel": "^7.1.4",
"ember-cli-htmlbars": "^2.0.1",
"ember-decorators": "^3.1.5",
"intl-tel-input": "^14.0.7"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"@ember/jquery": "^0.5.2",
"@ember/optional-features": "^0.7.0",
"broccoli-asset-rev": "^2.7.0",
Expand Down
9 changes: 4 additions & 5 deletions tests/dummy/app/pods/application/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Route from '@ember/routing/route'
import { service } from '@ember-decorators/service'
import { inject as service } from '@ember/service'

export default class ApplicationRoute extends Route {
@service
phoneInput
export default Route.extend({
phoneInput: service(),

async beforeModel() {
await this.get('phoneInput').load()
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,3 @@ export default Component.extend({
// END-SNIPPET
}
})

// import Controller from '@ember/controller'
// import { action } from '@ember-decorators/object'

// export default class DocsUsageController extends Controller {
// @action
// handleUpdate(number, metaData) {
// this.set('number', number)
// this.setProperties(metaData)
// }
// }
6 changes: 3 additions & 3 deletions tests/integration/components/phone-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import hbs from 'htmlbars-inline-precompile'
module('Integration | Component | phone-input', function(hooks) {
setupRenderingTest(hooks)

test('it renders an input of type tel', async function(assert) {
test('renders an input of type tel', async function(assert) {
assert.expect(1)

await this.owner.lookup('service:phone-input').load()
Expand All @@ -16,7 +16,7 @@ module('Integration | Component | phone-input', function(hooks) {
assert.dom('input').hasAttribute('type', 'tel')
})

test('it renders the value', async function(assert) {
test('renders the value', async function(assert) {
assert.expect(3)

await this.owner.lookup('service:phone-input').load()
Expand All @@ -39,7 +39,7 @@ module('Integration | Component | phone-input', function(hooks) {
assert.dom('input').hasValue(newValue)
})

test('it can update the country', async function(assert) {
test('can update the country', async function(assert) {
assert.expect(2)

await this.owner.lookup('service:phone-input').load()
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/services/phone-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module('Unit | Service | phone-input', function(hooks) {

const service = this.owner.lookup('service:phone-input')

const url = `assets/ember-phone-input/scripts/intlTelInput.min.js`
const url = 'assets/ember-phone-input/scripts/intlTelInput.min.js'

const expectedUrl = `assets/ember-phone-input/scripts/intlTelInput.min.js`
const expectedUrl = 'assets/ember-phone-input/scripts/intlTelInput.min.js'
assert.equal(service._loadUrl(url), expectedUrl)
})

Expand All @@ -22,9 +22,9 @@ module('Unit | Service | phone-input', function(hooks) {

const service = this.owner.lookup('service:phone-input')

const url = `assets/ember-phone-input/scripts/intlTelInput.min.js`
const url = 'assets/ember-phone-input/scripts/intlTelInput.min.js'

const expectedUrl = `/assets/ember-phone-input/scripts/intlTelInput.min.js`
const expectedUrl = '/assets/ember-phone-input/scripts/intlTelInput.min.js'
assert.equal(service._loadUrl(url), expectedUrl)
})
})
Loading