Skip to content

Commit

Permalink
Move initial @disabled state above event callbacks
Browse files Browse the repository at this point in the history
So the `@on-edit-off` event callback is not triggered initially.
  • Loading branch information
Panman82 committed Nov 22, 2019
1 parent caad631 commit b750125
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
12 changes: 7 additions & 5 deletions addon/components/froala-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ export default class FroalaEditorComponent extends Component {
editor.component = this;
this.editor = editor;

// Handle the initial @disabled state
// Note: Run before the event callbacks are added,
// so the @on-edit-off callback isn't triggered
if (this.args.disabled) {
this.editor.edit.off();
}

// Call the combinedCallbacks getter once
let callbacks = this.combinedCallbacks;

Expand All @@ -234,11 +241,6 @@ export default class FroalaEditorComponent extends Component {
// Add destroyed callback so the editor can be unreferenced
this.editor.events.on('destroy', froalaArg(this.teardownEditor), false); // false = run last

// Handle the initial @disabled state
if (this.args.disabled) {
this.editor.edit.off();
}

// Since we overrode this event callback,
// call the passed in callback(s) if there are any
if (initEventCallback === 'function') {
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/components/froala-editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,34 @@ module('Integration | Component | froala-editor', function(hooks) {
});


test('initial @disabled state does not double trigger the @on-edit-off callback', async function(assert) {
assert.expect(2);

this.set('disabled', true);

this.set('disableDisabled', () => {
this.set('disabled', false);
});

this.set('editOn', () => {
assert.ok(true);
this.set('disabled', true);
});

this.set('editOff', () => {
assert.ok(true);
});

await render(hbs`
<FroalaEditor
@disabled={{this.disabled}}
@on-initialized={{this.disableDisabled}}
@on-edit-on={{this.editOn}}
@on-edit-off={{this.editOff}}
/>
`);

});


});

0 comments on commit b750125

Please sign in to comment.