Events
VC is yelling about everything it is doing via events. Events are being called sequentially/synchronously in order of subscription. You can find events by either going through the codebase or toggling the 'lab' icon on the log page of main window. All of the methods in the following examples belong to Events object and to have been put on the global scope for convenience.
Subscribing
let myCallBack = function (some, args, orMaybe, not) {}
// single event
subscribe( 'someEvent', myCallBack )
// single event, will unsubscribe after invocation
once( 'someEvent', myCallBack )
// multiple at once
subscribe( ['someEvent', 'anotherEvent'], myCallBack )
Unsubscribing
unsubscribe( 'someEvent', myCallBack )
unsubscribe( 'someEvent', [myCallBack, myCallBack2] )
Event types
We use different convenience methods for emitting events:
emit=> event, message normally hidden from UIlog=> event , green messagenotify=> event , purple message , system notificationwarning=> event , yellow messageerror=> event , red messagedebug=> no event, black messagemutate=> special event, orange message
Mutation event
A reducer. Subscribers can mutate passed argument.
subscribe('shouldStringBePasted', function(shouldPaste) {
// Please don't overwrite.
// shouldPaste = {yesNo: false} <-- no-no
if (Scope.active('vmware-fusion')) {
// mutate the value
shouldPaste.yesNo = false
// stop mutation here, skipping other subscribers
shouldPaste["continue"] = false
}
// MUST return, regardless if changed
return shouldPaste
})
// excerpt from darwin package
var shouldPaste; // define object to pass through subscribers
shouldPaste = {
yesNo: false
}
shouldPaste = mutate('shouldStringBePasted', shouldPaste);
if (shouldPaste.yesNo === true) {
// do copy-paste
} else {
// do typing instead
}