Manually triggering actions for a rule
Please note this code needs to be tested in more use cases, it will require an effort from you to understand and use it. Please send us feedback about your success or fixes.
This is how to trigger currently the actions for an event, on all the nodes it is bound to:
var binderinfo = kukit.engine.binderInfoRegistry.getSingletonBinderInfoByName(
namespace, eventname);
var instance = binderinfo.getBinderInstance();
instance.__continueEvent_allNodes__(eventname, {});
To explain a bit:
First we need to get the binder information for a given event name. We also need the namespace, in case of "click" for example, the namespace will be null.
The singleton event binder means, in most of the cases we do not specify an event binder id in the kss rule. That is we could have a kss rule that is not singleton but has an explicit binder id like:
css_selector:click(binder_id) {Here binder_id would be a string. This will cause the creation of a separate binder instance that is registered with this identifier. A binder instance also represents a state. Kss rules between different identifier do not merge, so this can be used to bind a group of different events together and handle them together. This is only needed for more complex, stateful events. Normally the (binder_id) is omitted and kss creates a "singleton instance" by default.
...
}
css_selector:click {
...
}
This is the singleton binder instance, that we need to fetch in case of a click event or any builtin browser events. The next line will get the desired binder information from the registry.
var binderinfo = kukit.engine.binderInfoRegistry.getSingletonBinderInfoByName(
namespace, eventname);
From the binder info, we can easily acquire the binder instance itself:
var instance = binderinfo.getBinderInstance();
Finally we call the event continuation (=trigger the events) on the binder instance. We want the actions executed on all nodes that are bound from within the given kss rule.
instance.__continueEvent_allNodes__(eventname, {});
We will provide a commodity interface for this in the next version of kss.
Calling the event on just one node
In this case you need to use the call:
instance.__continueEvent__(eventname, node, {});
Use a binder id
In this case we really have a rule with a binder id:css_selector:click(binder_id) {And we want to call it instead of the singleton. Then we need to use:
...
}
var binderinfo = kukit.engine.binderInfoRegistry.getBinderInfoById(
'binder_id');
var instance = binderinfo.getBinderInstance();
instance.__continueEvent_allNodes__(eventname, {});
Triggering an event an all nodes, on all the binder ids
In this case we would want to trigger an event on all the nodes, on all the binder ids. Currently this is not easy because there is no api provided for this. This is however what would actually happen normally, when a node is clicked by the user, that is, the event happens naturally as bound, and not programmatically.Using your own custom event
It is also possible that you do not want to call an existing event but you just want your custom actions to happen. For this you can use the above described method with your own event. In addition you need to define your event, because kss will check if the event you trigger exists:
kukit.eventsGlobalRegistry.register('mynamespace', 'myevent',
function() {}, null, null);
This will register a very dummy event that does not do anything, neither has a binding itself, nor has a default action to execute when triggered. But you can then use this event from kss:
css_selector:mynamespace-myevent {
...
}
And you can trigger this event programmatically from javascript code, with the above described technique.
The event can be bound differently to different nodes, and the actions and parameters will change according to the node you bind to. If you do not want to have different parameters on different nodes, you can also omit the css selector, and use:
behaviour:mynamespace-myevent {
...
}
In this case however you need to use the call:
instance.__continueEvent__(eventname, null, {});This specifies you want to call the event exactly once,and without any useful node context.