Skip to content

Commit

Permalink
Fire editorUpdate event when UI state is updated
Browse files Browse the repository at this point in the history
Fixes #366
  • Loading branch information
jbalsas committed Nov 2, 2015
1 parent 0b9c91d commit a1f0ef9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ui/react/src/components/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,20 @@
componentDidUpdate: function (prevProps, prevState) {
var domNode = React.findDOMNode(this);

var editor = this.props.editor.get('nativeEditor');

if (domNode) {
this.props.editor.get('nativeEditor').fire('ariaUpdate', {
editor.fire('ariaUpdate', {
message: this._getAvailableToolbarsMessage(domNode)
});
}

editor.fire('editorUpdate', {
prevProps: prevProps,
prevState: prevState,
props: this.props,
state: this.state
});
},

_getAriaUpdateTemplate: function(ariaUpdate) {
Expand Down
28 changes: 28 additions & 0 deletions src/ui/react/test/alloy-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@
});
});

describe('UI component integration', function() {
beforeEach(function(done) {
initEditor.call(this, done);
});

afterEach(function() {
cleanUpEditor.call(this);
});

it('should fire an editorUpdate event when the component state changes', function(done) {
var onEditorUpdate = sinon.stub();

var alloyEditor = this.alloyEditor;

var nativeEditor = alloyEditor.get('nativeEditor');

nativeEditor.on('editorUpdate', onEditorUpdate);

nativeEditor.on('uiReady', function() {
alloyEditor._mainUI.setState({hidden: true});

assert.ok(onEditorUpdate.calledOnce);

done();
});
});
});

it('should create an instance when the passed srcNode is a DOM element', function(done) {
var el = document.createElement('div');
el.setAttribute('id', 'editable1');
Expand Down

0 comments on commit a1f0ef9

Please sign in to comment.