jimsparkman / RiotControl

Event Controller / Dispatcher For RiotJS, Inspired By Flux
http://jimsparkman.github.io/RiotControl/routing_demo/
MIT License
598 stars 48 forks source link

RiotControl Gotchas #34

Open ghstahl opened 8 years ago

ghstahl commented 8 years ago

Can we start a Gotchas readme?

RiotControl .on and .off need to match in your riotjs tags.
Don't forget to unregister your RiotControl event handlers if you are registering them in your mount.

<myTag>
<script>
        var self = this;
         self.onAspNetRolesChanged = (data) =>{
            console.log('aspnet_roles_changed',data)
         }
         self.onAspNetUserChanged= (data) =>{
            console.log('aspnet_user_changed',data)
         }
        self.on('before-mount',function(){
            console.log('on before-mount: aspnet-user-detail');
            RiotControl.on('aspnet_roles_changed', self.onAspNetRolesChanged);
            RiotControl.on('aspnet_user_changed', self.onAspNetUserChanged);
        });
        self.on('unmount', function() {
            RiotControl.off('aspnet_roles_changed', self.onAspNetRolesChanged);
            RiotControl.off('aspnet_user_changed', self.onAspNetUserChanged);
        })
</script>
</myTag>

I was wondering why my self.onAspNetUserChanged kept stacking. On every subsequent mount, I was adding a new event handler.

tooolbox commented 7 years ago

Goes along with #18