diff --git a/.travis.yml b/.travis.yml index 0f1eaad..e2d2e48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,11 +21,10 @@ env: matrix: # we recommend new addons test the current and previous LTS # as well as latest stable release (bonus points to beta/canary) - - EMBER_TRY_SCENARIO=ember-lts-2.12 - - EMBER_TRY_SCENARIO=ember-lts-2.16 - - EMBER_TRY_SCENARIO=ember-lts-2.18 - EMBER_TRY_SCENARIO=ember-lts-3.8 - EMBER_TRY_SCENARIO=ember-lts-3.12 + - EMBER_TRY_SCENARIO=ember-lts-3.16 + - EMBER_TRY_SCENARIO=ember-lts-3.20 - EMBER_TRY_SCENARIO=ember-release - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary diff --git a/addon/event_dispatcher.js b/addon/event_dispatcher.js index 4c04e4d..ca389ca 100644 --- a/addon/event_dispatcher.js +++ b/addon/event_dispatcher.js @@ -1,5 +1,5 @@ import { getOwner } from '@ember/application'; -import { merge, assign as _assign } from '@ember/polyfills'; +import { merge } from '@ember/polyfills'; import { get, set } from '@ember/object'; import Ember from 'ember'; import defaultHammerEvents from './hammer-events'; @@ -21,7 +21,7 @@ const eventEndings = { tap: [] }; -const assign = _assign || merge; +const assign = Object.assign || merge; const notFocusableTypes = ['submit', 'file', 'button', 'hidden', 'reset', 'range', 'radio', 'image', 'checkbox']; diff --git a/addon/modifiers/recognize-gesture.js b/addon/modifiers/recognize-gesture.js index 40375c4..64bfa80 100644 --- a/addon/modifiers/recognize-gesture.js +++ b/addon/modifiers/recognize-gesture.js @@ -1,55 +1,58 @@ - -import Modifier from 'ember-class-based-modifier'; -import { getOwner } from '@ember/application'; +import Modifier from "ember-modifier"; +import { registerDestructor } from "@ember/destroyable"; + +function cleanup(instance) { + if (instance.manager !== null) { + instance.manager.destroy(); + instance.manager = null; + } +} export default class RecognizeGestureModifier extends Modifier { - - constructor() { - super(...arguments); - this.recognizers = null; - this.manager = null; - this.gestures = getOwner(this).lookup('service:-gestures'); - - if (this.args.positional) { - this.recognizers = this.gestures.retrieve(this.args.positional); - } - this.managerOptions = (this.args.named && (Object.keys(this.args.named).length > 0)) ? Object.assign({}, this.args.named) : { domEvents: true }; - this.managerOptions.useCapture = this.gestures.useCapture; - - } - - didInstall() { - if (!this.recognizers) return; - this.element.style['touch-action'] = 'manipulation'; - this.element.style['-ms-touch-action'] = 'manipulation'; - this.recognizers.then ( (recognizers) => { - if (this.isDestroyed) return; - this.sortRecognizers(recognizers); - this.manager = new Hammer.Manager(this.element, this.managerOptions); - recognizers.forEach((recognizer) => { this.manager.add(recognizer); }); + constructor(owner) { + super(...arguments); + this.gestures = owner.lookup("service:-gestures"); + + registerDestructor(this, cleanup); + } + + modify(element, positional, named) { + const gestureNames = [...positional]; + this.recognizers = this.gestures.retrieve(gestureNames); + const managerOptions = + named && Object.keys(named).length > 0 + ? Object.assign({}, named) + : { domEvents: true }; + managerOptions.useCapture = this.gestures.useCapture; + if (this.recognizers) { + element.style["touch-action"] = "manipulation"; + element.style["-ms-touch-action"] = "manipulation"; + this.recognizers.then((recognizers) => { + if (this.isDestroyed) return; + this.sortRecognizers(recognizers); + this.manager = new Hammer.Manager(element, managerOptions); + recognizers.forEach((recognizer) => { + this.manager.add(recognizer); }); + }); } - - willRemove() { - this.manager.destroy(); - this.manager = null; - } - - // Move each recognizer after all recognizers it excludes in the list - why? - sortRecognizers(recognizers) { - for (let i = 0; i < recognizers.length; i++) { - const r = recognizers[i]; - let currentIndex = i; - if (r.exclude.length) { - for (let j = 0; j < r.exclude.length; j++) { - const newIndex = recognizers.indexOf(r.exclude[j]); - if (newIndex > 0 && currentIndex < newIndex) { - recognizers.splice(currentIndex, 1); - recognizers.splice(newIndex, 0, r); - currentIndex = newIndex; - } - } - } + } + + // Move each recognizer after all recognizers it excludes in the list - why? + sortRecognizers(recognizers) { + for (let i = 0; i < recognizers.length; i++) { + const r = recognizers[i]; + let currentIndex = i; + if (r.exclude.length) { + for (let j = 0; j < r.exclude.length; j++) { + const newIndex = recognizers.indexOf(r.exclude[j]); + if (newIndex > 0 && currentIndex < newIndex) { + recognizers.splice(currentIndex, 1); + recognizers.splice(newIndex, 0, r); + currentIndex = newIndex; + } } + } } + } } diff --git a/addon/services/-gestures.js b/addon/services/-gestures.js index 6cc3ebb..6fc2621 100644 --- a/addon/services/-gestures.js +++ b/addon/services/-gestures.js @@ -1,28 +1,33 @@ -import { computed } from '@ember/object'; -import { getOwner } from '@ember/application'; -import Service from '@ember/service'; -import RSVP from 'rsvp'; -import camelize from '../utils/string/dasherized-to-camel'; -import capitalize from '../utils/string/capitalize-word'; +import { getOwner } from "@ember/application"; +import Service from "@ember/service"; +import RSVP from "rsvp"; +import camelize from "../utils/string/dasherized-to-camel"; +import capitalize from "../utils/string/capitalize-word"; const { - Promise, // jshint ignore:line - defer // jshint ignore:line + Promise, // jshint ignore:line + defer, // jshint ignore:line } = RSVP; -export default Service.extend({ +export default class Gestures extends Service { + _recognizers = {}; - _recognizers: null, - _fastboot: computed(function() { + get _fastboot() { let owner = getOwner(this); - return owner.lookup('service:fastboot'); - }), + return owner.lookup("service:fastboot"); + } + + get isFastBoot() { + return this._fastboot && this._fastboot.isFastBoot; + } retrieve(names) { - let promises = names.map((name) => { return this.lookupRecognizer(name); }); + let promises = names.map((name) => { + return this.lookupRecognizer(name); + }); return RSVP.all(promises); - }, + } createRecognizer(name, details) { const eventName = camelize(details.eventName || name).toLowerCase(); @@ -35,51 +40,55 @@ export default Service.extend({ const Recognizer = new Hammer[gesture](options); Recognizer.initialize = defer(); - this.set(`_recognizers.${name}`, Recognizer); + this._recognizers[name] = Recognizer; return Recognizer; - }, + } setupRecognizer(name, details) { - if (this.get('_fastboot.isFastBoot')) { return; } - return Promise.resolve(this.createRecognizer(name, details)) - - // includes - .then((Recognizer) => { - if (details.include) { - const included = details.include.map((name) => { - return this.__speedyLookupRecognizer(name); - }); - return RSVP.all(included).then((recognizers) => { - Recognizer.recognizeWith(recognizers); - return Recognizer; - }); - } - return Recognizer; - }) - - // excludes - .then((Recognizer) => { - if (details.exclude) { - const excluded = details.exclude.map((name) => { - return this.__speedyLookupRecognizer(name); - }); - - return RSVP.all(excluded).then((recognizers) => { - Recognizer.requireFailure(recognizers); - Recognizer.exclude = recognizers; + if (this.isFastBoot) { + return; + } + return ( + Promise.resolve(this.createRecognizer(name, details)) + + // includes + .then((Recognizer) => { + if (details.include) { + const included = details.include.map((name) => { + return this.__speedyLookupRecognizer(name); + }); + return RSVP.all(included).then((recognizers) => { + Recognizer.recognizeWith(recognizers); + return Recognizer; + }); + } + return Recognizer; + }) + + // excludes + .then((Recognizer) => { + if (details.exclude) { + const excluded = details.exclude.map((name) => { + return this.__speedyLookupRecognizer(name); + }); + + return RSVP.all(excluded).then((recognizers) => { + Recognizer.requireFailure(recognizers); + Recognizer.exclude = recognizers; + Recognizer.initialize.resolve(Recognizer); + return Recognizer; + }); + } else { + Recognizer.exclude = []; Recognizer.initialize.resolve(Recognizer); return Recognizer; - }); - } else { - Recognizer.exclude = []; - Recognizer.initialize.resolve(Recognizer); - return Recognizer; - } - }); - }, + } + }) + ); + } __speedyLookupRecognizer(name) { - let recognizer = this.get(`_recognizers.${name}`); + let recognizer = this._recognizers[name]; if (recognizer) { return recognizer; } @@ -91,14 +100,17 @@ export default Service.extend({ return this.setupRecognizer(name, details.class); } - return Promise.reject(new Error(`ember-gestures/recognizers/${name} was not found. You can scaffold this recognizer with 'ember g recognizer ${name}'`)); - - }, + return Promise.reject( + new Error( + `ember-gestures/recognizers/${name} was not found. You can scaffold this recognizer with 'ember g recognizer ${name}'` + ) + ); + } lookupRecognizer(name) { - let recognizer = this.get(`_recognizers.${name}`); + let recognizer = this._recognizers[name]; if (recognizer) { - return recognizer.initialize.promise.then(function(recognizer) { + return recognizer.initialize.promise.then(function (recognizer) { return recognizer; }); } @@ -110,12 +122,10 @@ export default Service.extend({ return this.setupRecognizer(name, details.class); } - return Promise.reject(new Error(`ember-gestures/recognizers/${name} was not found. You can scaffold this recognizer with 'ember g recognizer ${name}'`)); - }, - - init() { - this._super(); - this._recognizers = {}; + return Promise.reject( + new Error( + `ember-gestures/recognizers/${name} was not found. You can scaffold this recognizer with 'ember g recognizer ${name}'` + ) + ); } - -}); +} diff --git a/app/event_dispatcher.js b/app/event_dispatcher.js index fe0faeb..8c5387b 100644 --- a/app/event_dispatcher.js +++ b/app/event_dispatcher.js @@ -1,10 +1,9 @@ -import { merge, assign as _assign } from '@ember/polyfills'; - +import { merge } from '@ember/polyfills'; import EventDispatcher from 'ember-gestures/event_dispatcher'; import config from './config/environment'; -const assign = _assign || merge; +const assign = Object.assign || merge; let gestures = assign({}, { emberUseCapture: false, diff --git a/app/services/-gestures.js b/app/services/-gestures.js index 46b21f0..2a0c8af 100644 --- a/app/services/-gestures.js +++ b/app/services/-gestures.js @@ -1,8 +1,8 @@ -import { merge, assign as _assign } from '@ember/polyfills'; +import { merge } from '@ember/polyfills'; import config from '../config/environment'; import Service from 'ember-gestures/services/-gestures'; -const assign = _assign || merge; +const assign = Object.assign || merge; let gestures = assign({}, { useCapture: false diff --git a/config/ember-try.js b/config/ember-try.js index 693de8a..d9da4ec 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -59,6 +59,22 @@ module.exports = function() { } } }, + { + name: 'ember-lts-3.16', + npm: { + devDependencies: { + 'ember-source': '~3.16.0' + } + } + }, + { + name: 'ember-lts-3.20', + npm: { + devDependencies: { + 'ember-source': '~3.20.0' + } + } + }, { name: 'ember-release', npm: { diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..f408cac --- /dev/null +++ b/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file diff --git a/package.json b/package.json index 4432a54..23c00ab 100644 --- a/package.json +++ b/package.json @@ -43,11 +43,11 @@ "animation-frame": "~0.2.4", "broccoli-funnel": "^2.0.2", "broccoli-merge-trees": "^3.0.2", - "ember-class-based-modifier": "^0.10.0", "ember-cli-babel": "^7.7.0", "ember-cli-htmlbars": "^2.0.1", "ember-cli-version-checker": "^2.1.0", "ember-copy": "^2.0.0", + "ember-modifier": "^2.1.1", "fastboot-transform": "^0.1.3", "hammerjs": "^2.0.8", "resolve": "^1.10.0" @@ -73,7 +73,7 @@ "ember-on-modifier": "1.0.0", "ember-qunit": "^4.5.1", "ember-resolver": "^4.0.0", - "ember-source": "~3.1.0", + "ember-source": "~3.3.0", "ember-source-channel-url": "^1.0.1", "ember-try": "^0.2.23", "eslint-plugin-ember": "^5.0.0",