Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
OicResource: Rename update event to change
Browse files Browse the repository at this point in the history
Change-Id: I93c0c3f1956612fc234da3ffbf6b4477c633601e
  • Loading branch information
Gabriel Schulhof committed Apr 22, 2016
1 parent a2ece68 commit 472f99f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions js/high-level-client-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ device.addEventListener( "resourcefound", function( event ) {

// Stop observing after having made 10 observations
if ( ++observationCount >= 10 ) {
event.resource.removeEventListener( "update", resourceUpdate );
event.resource.removeEventListener( "change", resourceUpdate );
}
};

console.log( "This is the resource we want to observe" );

// Let's start observing the resource.
event.resource.addEventListener( "update", resourceUpdate );
event.resource.addEventListener( "change", resourceUpdate );
}
} );
device.findResources().catch( function( error ) {
Expand Down
14 changes: 7 additions & 7 deletions lib/OicResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = require( "lodash" ),
var result,
observationHandleReceptacle = {};

if ( !( event === "update" && listenerCount( this, event ) === 0 ) ) {
if ( !( event === "change" && listenerCount( this, event ) === 0 ) ) {
return;
}

Expand All @@ -67,8 +67,8 @@ var _ = require( "lodash" ),
_.extend( this.properties,
utils.payloadToObject( response.payload.values ) );
}
this.dispatchEvent( "update", {
type: "update",
this.dispatchEvent( "change", {
type: "change",
resource: this
} );
return iotivity.OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION;
Expand All @@ -87,7 +87,7 @@ var _ = require( "lodash" ),
this.on( "removeListener", _.bind( function( event ) {
var result;

if ( !( event === "update" && this._observationHandle &&
if ( !( event === "change" && this._observationHandle &&
listenerCount( this, event ) === 0 ) ) {
return;
}
Expand All @@ -106,9 +106,9 @@ var _ = require( "lodash" ),
}
}, this ) );

// Define property "onresourceupdate" such that writing to it will result in handlers being
// added to/removed from the "resourceupdate" event
utils.addLegacyEventHandler( this, "update" );
// Define property "onchange" such that writing to it will result in handlers being
// added to/removed from the "change" event
utils.addLegacyEventHandler( this, "change" );
};

utils.makeEventEmitter( OicResource ).prototype._isOicResource = true;
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/API Observation/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ function discoverResources() {
},
resourceUpdate = function( event ) {
if ( event.resource.properties.increment >= 9 ) {
event.resource.onupdate = null;
event.resource.onchange = null;
utils.assert( "deepEqual", event.resource._observationHandle,
observationHandle,
"Client: Private resource observation handle is unchanged after " +
"removing handler via legacy interface" );
event.resource.removeEventListener( "update", dummyHandler );
event.resource.removeEventListener( "change", dummyHandler );
utils.assert( "deepEqual", event.resource._observationHandle,
observationHandle,
"Client: Private resource observation handle is unchanged after " +
"removing dummy handler" );
event.resource.removeEventListener( "update", resourceUpdate );
event.resource.removeEventListener( "change", resourceUpdate );
utils.assert( "ok", !event.resource._observationHandle,
"Client: Private resource observation handle is absent after " +
"removing the last handler" );
Expand All @@ -55,13 +55,13 @@ function discoverResources() {
resourceFound = true;
utils.assert( "ok", !event.resource._observationHandle,
"Client: Private resource observation handle is initially absent" );
event.resource.addEventListener( "update", resourceUpdate );
event.resource.addEventListener( "change", resourceUpdate );
observationHandle = event.resource._observationHandle;
event.resource.addEventListener( "update", dummyHandler );
event.resource.addEventListener( "change", dummyHandler );
utils.assert( "deepEqual", event.resource._observationHandle, observationHandle,
"Client: Private resource observation handle is unchanged after adding a second " +
"handler" );
event.resource.onupdate = legacyResourceUpdate;
event.resource.onchange = legacyResourceUpdate;
utils.assert( "deepEqual", event.resource._observationHandle, observationHandle,
"Client: Private resource observation handle is unchanged after adding a " +
"handler via the legacy interface" );
Expand Down

0 comments on commit 472f99f

Please sign in to comment.