Module-documentation

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

Filtering subscription

Using the optional filter-argument, you can define a very specific filter for the subscriber. Note that it is more common not to use a specific filter, but do filtering by specifying an emitterName. This example filters by a filterfunction. Note that we need to pass the filterfunction as 4th parameter, not the 3rd.

Click on the buttons. Only the buttons with age>50 will show a pop-up.


Code-example:

<body>
    <button id="button1" class="pure-button pure-button-primary pure-button-bordered">Click me to save without age</button><br>
    <button id="button2" class="pure-button pure-button-primary pure-button-bordered">Click me to save with age=65</button>
</body>
<script src="itsabuild-min.js"></script>
<script>
    ITSA.Event.after(
        '*:save',
        function(e) {
            alert('saved with age '+e.age+' years');
        },
        null,
        function(e) {
            return (e.age>50);
        }
    );

    ITSA.Event.after(
        'tap',
        function() {
            ITSA.Event.emit('object1:save');
        },
        '#button1'
    );

    ITSA.Event.after(
        'tap',
        function() {
            ITSA.Event.emit('object2:save', {age: 65});
        },
        '#button2'
    );
</script>
API Docs