mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs_ci: check all md files except thirdparty (#6855)
This commit is contained in:
@@ -10,7 +10,8 @@ A module to provide eventing capabilities using pub/sub.
|
||||
|
||||
**EventBus:**
|
||||
|
||||
1. `publish(name string, sender voidptr, args voidptr)` - publish an event with provided Params & name
|
||||
1. `publish(name string, sender voidptr, args voidptr)` - publish an event with provided
|
||||
Params & name
|
||||
2. `clear_all()` - clear all subscribers
|
||||
3. `has_subscriber(name string)` - check if a subscriber to an event exists
|
||||
|
||||
@@ -18,7 +19,9 @@ A module to provide eventing capabilities using pub/sub.
|
||||
|
||||
1. `subscribe(name string, handler EventHandlerFn)` - subscribe to an event
|
||||
2. `subscribe_once(name string, handler EventHandlerFn)` - subscribe only once to an event
|
||||
3. `subscribe_method(name string, handler EventHandlerFn, receiver voidptr)` - subscribe to an event and also set the `receiver` as a parameter. Since it's not yet possible to send methods as parameters, this is a workaround.
|
||||
3. `subscribe_method(name string, handler EventHandlerFn, receiver voidptr)` - subscribe to
|
||||
an event and also set the `receiver` as a parameter.
|
||||
Since it's not yet possible to send methods as parameters, this is a workaround.
|
||||
4. `is_subscribed(name string)` - check if we are subscribed to an event
|
||||
5. `unsubscribe(name string)` - unsubscribe from an event
|
||||
|
||||
@@ -26,9 +29,8 @@ A module to provide eventing capabilities using pub/sub.
|
||||
|
||||
The function given to `subscribe`, `subscribe_method` and `subscribe_once` must match this:
|
||||
|
||||
```v
|
||||
fn(receiver voidptr, args voidptr, sender voidptr){
|
||||
|
||||
```v oksyntax
|
||||
fn(receiver voidptr, args voidptr, sender voidptr) {
|
||||
}
|
||||
|
||||
// Since V can map structs to voidptr, this also works
|
||||
@@ -52,7 +54,7 @@ _Note: As a general rule, you will need to **subscribe before publishing**._
|
||||
|
||||
**main.v**
|
||||
|
||||
```v
|
||||
```v oksyntax
|
||||
module main
|
||||
import eventbus
|
||||
|
||||
@@ -78,7 +80,7 @@ fn on_error(receiver voidptr, e &Error, work &Work) {
|
||||
|
||||
**work.v**
|
||||
|
||||
```v
|
||||
```v oksyntax
|
||||
module main
|
||||
|
||||
struct Work{
|
||||
@@ -100,12 +102,15 @@ fn do_work(){
|
||||
|
||||
### Notes:
|
||||
|
||||
1. Each `EventBus` instance has it's own registry (i.e. there is no global event registry so you can't just subscribe to an event wherever you are.
|
||||
2. Each `EventBus` has a `Subscriber` instance which will need to be either exposed or you can make small public helper functions specific to your module like (`onPress`, `onError`) and etc.
|
||||
3. The `eventbus` module has some helpers to ease getting/setting of Params (since V doesn't support empty interfaces yet or reflection) so use them (see usage above).
|
||||
1. Each `EventBus` instance has it's own registry (i.e. there is no global event registry
|
||||
so you can't just subscribe to an event wherever you are.
|
||||
2. Each `EventBus` has a `Subscriber` instance which will need to be either exposed or you can make
|
||||
small public helper functions specific to your module like (`onPress`, `onError`) and etc.
|
||||
3. The `eventbus` module has some helpers to ease getting/setting of Params
|
||||
(since V doesn't support empty interfaces yet or reflection) so use them (see usage above).
|
||||
|
||||
**The rationale behind separating Subscriber & Publisher:**
|
||||
|
||||
This is mainly for security because if publisher & subscriber are both passed around,
|
||||
a client can easily publish events acting as the server.
|
||||
This is mainly for security because if publisher & subscriber are both passed around,
|
||||
a client can easily publish events acting as the server.
|
||||
So a client should only be able to use the Subscriber methods.
|
||||
|
||||
Reference in New Issue
Block a user