diff options
author | Tim Buschtöns | 2014-02-04 13:56:57 +0000 |
---|---|---|
committer | Tim Buschtöns | 2014-02-04 13:56:57 +0000 |
commit | 87403ee4d9188565e59dcce8c3c365a9172bae15 (patch) | |
tree | 73e3a7d1d2f0d7a948414bae58561dbfe69e3b4f | |
parent | 422c3d246317ff3de4820ba67189e0354e500abc (diff) | |
download | org.eclipse.rap.incubator.dropdown-87403ee4d9188565e59dcce8c3c365a9172bae15.tar.gz org.eclipse.rap.incubator.dropdown-87403ee4d9188565e59dcce8c3c365a9172bae15.tar.xz org.eclipse.rap.incubator.dropdown-87403ee4d9188565e59dcce8c3c365a9172bae15.zip |
Fetch DataSource on next render event when dataSourceId changes
The DataSource object may not exist yet, therefore we have to wait until
after the render event.
3 files changed, 61 insertions, 2 deletions
diff --git a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js index c880bf8..12e0fd3 100644 --- a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js +++ b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js @@ -148,7 +148,12 @@ function syncModelTextSelection( textWidget, event ) { // Event Handling function onChangeDataSourceId( event ) { - this.set( "suggestions", null ); + var self = this; + var callback = function() { + self.set( "suggestions", null ); + rap.off( "render", callback ); + }; + rap.on( "render", callback ); } function onChangeSuggestions( event ) { diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/.jshintrc b/tests/org.eclipse.rap.addons.autosuggest.test/.jshintrc new file mode 100644 index 0000000..47b15b4 --- /dev/null +++ b/tests/org.eclipse.rap.addons.autosuggest.test/.jshintrc @@ -0,0 +1,29 @@ +{ + "curly": true, + "immed": true, + "newcap": true, + "eqnull": true, + "shadow": true, + "funcscope": true, + "undef": true, + "browser": true, + "laxbreak": true, + "evil": true, + "onecase": true, + "sub": true, + "globals": { + "rwt": true, + "rap": true, + "org": true, + "SWT": false, + "describe": false, + "it": false, + "expect": false, + "beforeEach": false, + "afterEach": false, + "spyOn": false, + "TestUtil": false, + "RapMock": true,
+ "jasmine": false + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js index 1621095..bba101a 100644 --- a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js +++ b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js @@ -145,6 +145,8 @@ beforeEach( function() { rap = new RapMock(); + spyOn( rap, "on" ); + spyOn( rap, "off" ); model = rap.typeHandler[ "rwt.remote.Model" ].factory(); // make model "public" model.set( "suggestions", [ "foo", "bar", "foobar", "banana", "apple", "cherry" ] ); log = []; @@ -159,15 +161,38 @@ describe( "change:dataSourceId", function() { - it( "sets suggestions to null", function() { + it( "does nothing before the next render event", function() { model.addListener( "change:dataSourceId", createClientListener( "AutoSuggest.js" ) ); model.set( "suggestions", [] ); model.set( "dataSourceId", "fooId" ); + expect( model.get( "suggestions" ) ).not.toBeNull(); + } ); + + it( "sets suggestions to null on the next render event", function() { + model.addListener( "change:dataSourceId", createClientListener( "AutoSuggest.js" ) ); + model.set( "suggestions", [] ); + + model.set( "dataSourceId", "fooId" ); + expect( rap.on ).toHaveBeenCalledWith( "render", jasmine.any( Function ) ); + var listener = rap.on.argsForCall[ 0 ][ 1 ]; + listener(); + expect( model.get( "suggestions" ) ).toBeNull(); } ); + it( "sets suggestions to null only once", function() { + model.addListener( "change:dataSourceId", createClientListener( "AutoSuggest.js" ) ); + model.set( "suggestions", [] ); + + model.set( "dataSourceId", "fooId" ); + var listener = rap.on.argsForCall[ 0 ][ 1 ]; + listener(); + + expect( rap.off ).toHaveBeenCalledWith( "render", listener ); + } ); + } ); describe( "change:userText", function() { |