Skip to content

Commit

Permalink
Added warnings to deprecated methods [#935]
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuck committed Mar 5, 2012
2 parents 99ffd5b + 5b18061 commit 02cb124
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 103 deletions.
49 changes: 38 additions & 11 deletions popcorn.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@


Popcorn.timeUpdate( self, {} ); Popcorn.timeUpdate( self, {} );


self.trigger( "timeupdate" ); self.emit( "timeupdate" );


!self.isDestroyed && requestAnimFrame( self.data.timeUpdate ); !self.isDestroyed && requestAnimFrame( self.data.timeUpdate );
}; };
Expand Down Expand Up @@ -545,7 +545,7 @@
_natives: { _natives: {
start: fn || Popcorn.nop, start: fn || Popcorn.nop,
end: Popcorn.nop, end: Popcorn.nop,
type: "exec" type: "cue"
} }
}); });


Expand All @@ -572,7 +572,7 @@
} }


// Trigger either muted|unmuted event // Trigger either muted|unmuted event
this.trigger( event ); this.emit( event );


return this; return this;
}, },
Expand Down Expand Up @@ -1116,7 +1116,7 @@
byEnd._running = false; byEnd._running = false;
natives.end.call( obj, event, byEnd ); natives.end.call( obj, event, byEnd );


obj.trigger( trackend, obj.emit( trackend,
Popcorn.extend({}, byEnd, { Popcorn.extend({}, byEnd, {
plugin: type, plugin: type,
type: trackend type: trackend
Expand Down Expand Up @@ -1150,7 +1150,7 @@
byStart._running = true; byStart._running = true;
natives.start.call( obj, event, byStart ); natives.start.call( obj, event, byStart );


obj.trigger( trackstart, obj.emit( trackstart,
Popcorn.extend({}, byStart, { Popcorn.extend({}, byStart, {
plugin: type, plugin: type,
type: trackstart type: trackstart
Expand Down Expand Up @@ -1207,7 +1207,7 @@
byStart._running = false; byStart._running = false;
natives.end.call( obj, event, byStart ); natives.end.call( obj, event, byStart );


obj.trigger( trackend, obj.emit( trackend,
Popcorn.extend({}, byEnd, { Popcorn.extend({}, byEnd, {
plugin: type, plugin: type,
type: trackend type: trackend
Expand Down Expand Up @@ -1240,7 +1240,7 @@
byEnd._running = true; byEnd._running = true;
natives.start.call( obj, event, byEnd ); natives.start.call( obj, event, byEnd );


obj.trigger( trackstart, obj.emit( trackstart,
Popcorn.extend({}, byStart, { Popcorn.extend({}, byStart, {
plugin: type, plugin: type,
type: trackstart type: trackstart
Expand Down Expand Up @@ -1476,7 +1476,7 @@


if ( reserved.indexOf( type ) === -1 ) { if ( reserved.indexOf( type ) === -1 ) {


this.listen( type, callback ); this.on( type, callback );
} }
} }


Expand All @@ -1488,11 +1488,11 @@
// Extend Popcorn.p with new named definition // Extend Popcorn.p with new named definition
// Assign new named definition // Assign new named definition
Popcorn.p[ name ] = plugin[ name ] = function( options ) { Popcorn.p[ name ] = plugin[ name ] = function( options ) {

// Merge with defaults if they exist, make sure per call is prioritized // Merge with defaults if they exist, make sure per call is prioritized
var defaults = ( this.options.defaults && this.options.defaults[ name ] ) || {}, var defaults = ( this.options.defaults && this.options.defaults[ name ] ) || {},
mergedSetupOpts = Popcorn.extend( {}, defaults, options ); mergedSetupOpts = Popcorn.extend( {}, defaults, options );

return pluginFn.call( this, isfn ? definition.call( this, mergedSetupOpts ) : definition, return pluginFn.call( this, isfn ? definition.call( this, mergedSetupOpts ) : definition,
mergedSetupOpts ); mergedSetupOpts );
}; };
Expand Down Expand Up @@ -1540,7 +1540,7 @@


// Trigger an error that the instance can listen for // Trigger an error that the instance can listen for
// and react to // and react to
this.trigger( "error", Popcorn.plugin.errors ); this.emit( "error", Popcorn.plugin.errors );
} }
}; };
} }
Expand Down Expand Up @@ -1889,6 +1889,33 @@
}) })
}; };


// Setup logging for deprecated methods
Popcorn.forEach({
// Deprecated: Recommended
"listen": "on",
"unlisten": "off",
"trigger": "emit",
"exec": "cue"

}, function( recommend, api ) {
var original = Popcorn.p[ api ];
// Override the deprecated api method with a method of the same name
// that logs a warning and defers to the new recommended method
Popcorn.p[ api ] = function() {
if ( console && console.warn ) {
console.warn(
"Deprecated method '" + api + "', " +
(recommend == null ? "do not use." : "use '" + recommend + "' instead." )
);

// Restore api after first warning
Popcorn.p[ api ] = original;
}
return Popcorn.p[ recommend ].apply( this, [].slice.call( arguments ) );
};
});


// Exposes Popcorn to global context // Exposes Popcorn to global context
global.Popcorn = Popcorn; global.Popcorn = Popcorn;


Expand Down
Loading

0 comments on commit 02cb124

Please sign in to comment.