Skip to content

Commit 852fe82

Browse files
committed
actions: set _interacting = true before start
Close taye#503
1 parent 4a77418 commit 852fe82

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/actions/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const actions = {
88
};
99

1010
Interaction.signals.on('action-start', function ({ interaction, event }) {
11-
firePrepared(interaction, event, 'start');
1211
interaction._interacting = true;
12+
firePrepared(interaction, event, 'start');
1313
});
1414

1515
Interaction.signals.on('action-move', function ({ interaction, event, preEnd }) {

tests/Interaction.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,55 @@ test('Interaction.start', t => {
296296

297297
t.end();
298298
});
299+
300+
test('action-{start,move,end} signal listeners', t => {
301+
const Interactable = require('../src/Interactable');
302+
const Interaction = require('../src/Interaction');
303+
304+
const interaction = new Interaction();
305+
const element = {};
306+
const interactable = new Interactable('TEST', { context: {} });
307+
308+
let interactingInStartListener = null;
309+
310+
interaction.target = interactable;
311+
interaction.element = element;
312+
interaction.prepared = { name: 'TEST' };
313+
314+
interactable.events.on('TESTstart', event => {
315+
interactingInStartListener = event.interaction.interacting();
316+
});
317+
318+
Interaction.signals.fire('action-start', { interaction, event: {} });
319+
320+
t.ok(interactingInStartListener, 'start event was fired correctly');
321+
322+
interactable.unset();
323+
324+
t.end();
325+
});
326+
327+
test('stop interaction from start event', t => {
328+
const Interactable = require('../src/Interactable');
329+
const Interaction = require('../src/Interaction');
330+
331+
const interaction = new Interaction();
332+
const element = {};
333+
const interactable = new Interactable('TEST', { context: {} });
334+
335+
interaction.target = interactable;
336+
interaction.element = element;
337+
interaction.prepared = { name: 'TEST' };
338+
339+
interactable.events.on('TESTstart', event => {
340+
event.interaction.stop();
341+
});
342+
343+
Interaction.signals.fire('action-start', { interaction, event: {} });
344+
345+
t.notOk(interaction.interacting(), 'interaction can be stopped from start event listener');
346+
347+
interactable.unset();
348+
349+
t.end();
350+
});

0 commit comments

Comments
 (0)