auth0 / webtask-widget

[BETA] Widget that can be embedded in websites to allow transparent creation of extension points or urls.
MIT License
10 stars 2 forks source link

Refactor widget architecture to support returned api objects #13

Closed ggoodman closed 9 years ago

ggoodman commented 9 years ago

The internal plumbing has been restructured so that:

  1. The Component layering of ComponentStack remains but the return value from ComponentStack#push() is now an object with the component and promise associated with the layer.
  2. All widget entry-points now return instances of the base class A0Widget that contains the architecture to defer calls until component mounting while maintaining transactional functionality (either through callback or returned Promise). A0Widget is also an instance of an EventEmitter and has the logic to map Component callback props to events.

This means you can do something like this:

    var editor = window.webtaskWidget.createEditor({
        mount: document.getElementById('editor'),
        storeProfile: true,
    });

    // You can listen for events on the returned 'smart' object
    editor.on('save', function (webtask) {
        console.log('save event', webtask);
    });

    // You can also initiate a save intent that will get executed once login and/or
    // profile retrieval has completed. The save method can accept a node-style 
    // callback and will return a Promise. If the user fails to log in, an error will
    // be sent to the node-style callback and the Promise will be rejected.
    editor.save()
        .then(function (webtask) {
            console.log('saved webtask', webtask);
        }, function (err) {
            console.log('error saving webtask', err);
        });