Module-documentation

version 1.0.0
module: itsa-event
maintanance: Marco Asbreuk
home
all modules

After save-event

After-events will not wait for any asynchronous default-function to finish, to keep performant. However, you can inspect e.returnValue: whenever that is a Promise, this Promise can be used to get informed when the default-function is ready.

Click on the button to send profile.

Code-example:

<script src="itsabuild-min.js"></script>
<script>
    var Member = ITSA.Classes.createClass(),
        url = 'http://servercors.itsa.io/example/delay',
        member;


var memberproto = {}.merge(ITSA.Event.Listener).merge(ITSA.Event.Emitter('PersonalProfile')),
    container = document.getElementById('target-container'),
    member = Object.create(memberproto);
    member.name = 'Marco';

    member.defineEvent('send') // defines "PersonalProfile:save"
         .defaultFn(function(e) {
             // do something and optionally return
             return ITSA.IO.send(url, this); // now available at e.returnValue
         });

    member.after('this:send', function(e) {
        container.innerHTML = 'starting sending...';
        e.returnValue.then(
            function(response) {
                container.innerHTML = response;
            },
            function(err) {
                container.innerHTML = err.message;
            }
        );
    });

    ITSA.Event.after(
        'tap',
        function() {
            member.emit('send');
        },
        '#buttongo'
    );
</script>
API Docs