Skip to content

Commit

Permalink
Merge pull request Polymer#4346 from Polymer/2.0-gestures-deprecated-api
Browse files Browse the repository at this point in the history
Add back deprecated Polymer.Gestures.add and Polymer.Gestures.remove
  • Loading branch information
dfreedm authored Feb 28, 2017
2 parents c6589a1 + 6170835 commit 0d06359
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,10 @@
gestures.findOriginalTarget = gestures._findOriginalTarget;

/** @deprecated */
gestures.add = gestures._add;
gestures.add = gestures.addListener;

/** @deprecated */
gestures.remove = gestures.removeListener;

Polymer.Gestures = gestures;

Expand Down
9 changes: 9 additions & 0 deletions test/unit/gestures-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,12 @@
});
</script>
</dom-module>

<dom-module id="x-imperative">
<script>
Polymer({
is: 'x-imperative',
behaviors: [EventCaptureBehavior]
})
</script>
</dom-module>
35 changes: 35 additions & 0 deletions test/unit/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,41 @@
});
});
});

suite('Imperative API', function() {
var el, fn;
suiteSetup(function() {
el = document.createElement('x-imperative');
document.body.appendChild(el);
fn = function(e) { el.handle(e) };
});
suiteTeardown(function() {
document.body.removeChild(el);
});

test('add listeners with addListener', function() {
Polymer.Gestures.addListener(el, 'down', fn);
Polymer.Gestures.add(el, 'up', fn);
var ev = new CustomEvent('mousedown', {bubbles: true, composed: true});
el.dispatchEvent(ev);
assert.equal(el.stream.length, 1);
assert.equal(el.stream[0].type, 'down');
ev = new CustomEvent('mouseup', {bubbles: true, composed: true});
el.dispatchEvent(ev);
assert.equal(el.stream.length, 2);
assert.equal(el.stream[1].type, 'up');
})

test('remove listeners with removeListener', function() {
Polymer.Gestures.remove(el, 'down', fn);
Polymer.Gestures.removeListener(el, 'up', fn);
var ev = new CustomEvent('mousedown', {bubbles: true, composed: true});
el.dispatchEvent(ev);
ev = new CustomEvent('mouseup', {bubbles: true, composed: true});
el.dispatchEvent(ev);
assert.equal(el.stream.length, 2);
})
});
</script>

</body>
Expand Down

0 comments on commit 0d06359

Please sign in to comment.