Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/defsquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/lmdbquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/statequark/stepperquark/storagequark/testquark/typesquark/uriquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_decoratorsquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.4.0 Documentation
Contents
-
quark/_event
- Class: Event
- Listen
- Listen2
- Class: EventNoticer
-
Class: Notification
- Notification
- notification.getNoticer(name)
- notification.hasNoticer(name)
- notification.addDefaultListener(name,listen)
- notification.trigger(name,data)
- notification.triggerWithEvent(name,event)
- notification.removeEventListener(name,listen?,ctx?)
- notification.removeEventListenerByCtx(ctx)
- notification.allNoticers()
- notification.triggerListenerChange(name,count,change)
- event(target,name)
quark/_event #
Class: Event #
Event #
The event data
Type parameters: Sender, SendData
event.returnValue #
The return value
returnValue: Uint
event.data #
The Data
readonly data: SendData
event.sender #
The sender
readonly sender: Sender
event.constructor(data) #
constructor(data: SendData)
Listen #
@callbackListen(this,evt)Type parameters:E,Ctx@paramthis:Ctx@paramevt:E
Listen2 #
@callbackListen2(self,evt)Type parameters:E,Ctx@paramself:Ctx@paramevt:E
Class: EventNoticer #
EventNoticer #
Event notifier, the core of event listener adding, deleting, triggering and notification
Type parameters: E
eventnoticer.name #
Event name
readonly name: string
eventnoticer.sender #
Event sender
readonly sender: any
eventnoticer.length #
Number of event listeners
readonly length:
eventnoticer.constructor(name,sender) #
constructor(name: string, sender: SenderOf<E>)
Parameters:
name— Event namesender— Event sender@paramlisten: Listening Function@paramctxOrId?: Specify the listener function this or id alias@paramid?: Listener alias, can be deleted by id
For example:
var ctx = { a:100 }
var id = screen.onChange.on(function(ev) {
// Prints: 100
console.log(this.a)
}, ctx)
// Replace Listener
screen.onChange.on(function(ev) {
// Prints: replace 100
console.log('replace', this.a)
}, ctx, id)
@paramlisten: Listening Function@paramctxOrId?: Specify the listener function this or id alias@paramid?: Listener alias, can be deleted by id
eventnoticer.forward(noticer,id?) #
Forward the event to another noticer
forward(noticer: EventNoticer<E>, id?: string): string
eventnoticer.trigger(data) #
Notify all observers
trigger(data: DataOf<E>)
eventnoticer.triggerWithEvent(e) #
Notify all observers
triggerWithEvent(e: E)
eventnoticer.off(listen?,ctx?) #
Remove listener function
off(listen?: Function | string, ctx?: object): Uint
Parameters:
listen?It can be a listener function/id alias. If no parameter is passed, all listeners will be uninstalled.ctx?— Context object, only valid whenlistenis a function
Returns: Returns the number of deleted listeners
eventnoticer.offByCtx(ctx) #
Remove all listeners related to ctx on this noticer
offByCtx(ctx: object): Uint
Class: Notification #
Notification #
This is a collection of events EventNoticer, event triggering and response center
Derived types inherited from it can use the @event keyword to declare member events
Type parameters: E
notification.getNoticer(name) #
getNoticer(name: string): EventNoticer<E>
notification.hasNoticer(name) #
hasNoticer(name: string): bool
notification.addDefaultListener(name,listen) #
addDefaultListener(name: string, listen: Listen<E2> | null)
Type parameters: E2
notification.trigger(name,data) #
Trigger an event by event name --> EventNoticer.trigger(data)
trigger(name: string, data: DataOf<E>)
notification.triggerWithEvent(name,event) #
Trigger an event by name and Event --> [EventNoticer.triggerWithEvent(event)]
triggerWithEvent(name: string, event: E)
notification.removeEventListener(name,listen?,ctx?) #
Remove listener function
removeEventListener(name: string, listen?: Function | string, ctx?: object)
Parameters:
name— Event namelisten?— It can be a listener function/id alias.If no parameter is passed, all listeners will be uninstalled.ctx?— Context object, only valid whenlistenis a function
notification.removeEventListenerByCtx(ctx) #
Delete all listeners related to ctx on notification
Actually traverse and call the EventNoticer.offByCtx(ctx) method
removeEventListenerByCtx(ctx: object)
For example:
import event from 'quark/event';
class TestNotification extends Notification {
\@event readonly onChange;
}
var notification = new TestNotification();
// Prints: responseonChange 0 100
notification.onChange = function(ev) { // add default listener
console.log('responseonChange 0', ev.data)
}
notification.triggerChange(100);
// Prints:
// responseonChange 0 200
// responseonChange 1
notification.onChange.on(function(ev) {
console.log('responseonChange 1')
})
notification.triggerWithEvent('change', new Event(200));
var noticer = notification.onChange;
noticer.off(0) // delete default listener
// Prints: responseonChange 1
notification.triggerChange();
notification.allNoticers() #
Get all of EventNoticer
allNoticers(): EventNoticer<E>[]
notification.triggerListenerChange(name,count,change) #
triggerListenerChange(name: string, count: Uint, change: Uint)
event(target,name) #
Typescript decorator
event(target: any, name: string)
@decorator