Most plugins utilize callbacks for providing integration points for end
developers. What are people's thoughts in regards to augmenting the event
framework to provide a "reverse callback" approach. This would decouple the
callbacks and possibly provide a common interface for multiple plugins which
then provide different implementations. Some psudo code below.

Arbitrary plugin which exports widgetShow and widgetHide events.

Developer code:
$('#myNode')
    .thePlugin()
    .bind('widgetShow', function(e) {
         ...
         e.returnValue( false );
         return false; // Cancel event propagation and other events
    })
    .bind('widgetHide', function(e) {
          ...
         e.returnValue('another value');
    });

<div id="myNode"></div>


Plugin Code:
...
    var showWidget = true;
    // Some point in the plugin a Show event should be triggered
    $(this).trigger('widgetShow', function(e) {
         var returnValues = e.returnValues();
         if (returnValues.length > 0) {
              if (returnValues[0] != true) {
                   showWidget = false;
              }
         }
    }
    if (!showWidget) {
         return false;
    }
...

This is somewhat similar in approach to the way the Qt framework provides
signals and slots. You could potentially have multiple event listeners so
widgets could potentially update themselves from events fired from other
components.

Thoughts?
-js

Reply via email to