klevu.extend( target [, object1 ] [, objectN ] ) Returns: Object
Description: Core events are custom build and executed events.
The event will generate a klevuChain there is no data or scope on the created chain. The chain will execute from the time of creation for maxCount times with an interval of delay or until the event evaluates to true via the fire function.
If the event has already executed any promise or attachment will be fired immediately.
Interfaces:
- build : function ( object ) – used to build a core event and define its functionality
- fire : function ( name ) – check if event chain can be executed and if yes execute it, stop the internal checking
- attach : function ( name , object ) – attach a function to event chain
- name is the name of the even declared when building the event
- object contains :
- name: name of the function to be executed – unique per event
- fire : source code of the execution
- A function can be sent instead of the object
- promise : function ( name , object ) – promise function to event chain , same as attach
When building a core event the following
- name – event name, must be unique and will be used as reference in the attachments. building a already defined event will override fire function and can lead to unforeseen situations.
- delay – used to reference the delay between checks in ms. Default 0 ms
- maxCount – maximum number of repetitions until the event is abandoned. Default 100
- fire – function source that returns true/false , will be used to check when event chain will fire
Example
klevu.coreEvent.build( { name : "testKlevuEvent", fire: function(){ if ( !klevu.isReady) { return false; } return true; }, maxCount: 500, delay:30 }); klevu.coreEvent.attach( "testKlevuEvent", function(){ console.log("Klevu is ready"); } );