Skip to content

Commit 5b9db5a

Browse files
committed
fix(observable): addWeakEventListener
1 parent 0e82e43 commit 5b9db5a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

content/core/observable.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ this.notifyPropertyChange('fruits', this.fruits)
7171

7272
### Avoiding Event Handler Memory Leak
7373

74-
To ensure that your app doesn't have memory leak caused by handlers that are no longer needed, use the [addWeakEventListener](#addweakeventlistener) function:
74+
To ensure that your app doesn't have memory leak caused by handlers that are no longer needed, use the [addWeakEventListener](#addweakeventlistener) function.
7575

7676
<!-- TODO: Add a working example -->
7777

@@ -144,21 +144,28 @@ Adds a one-time listener for the specified event.
144144

145145
### addWeakEventListener()
146146

147+
```ts
148+
observable.addWeakEventListener(source, eventName, callback, target)
149+
```
150+
151+
Attaches a Weak Event Listener.
152+
153+
- `source`: Observable class which emits the event.
154+
- `eventName`: The event name the specified listener listens to.
155+
- `callback`: The function which should be called when event occurs.
156+
- `target`: Subscriber (target) of the event listener. It will be used as a thisArg in the handler function.
157+
147158
### removeEventListener()
148159

149160
```ts
150-
Observable.removeEventListener(eventNames, callback, thisArg)
151-
152-
//or
153-
observable.removeEventListener(eventNames, callback, thisArg)
161+
observable.removeEventListener(eventNames, callback, target)
154162
```
155163

156164
Removes listener(s) for the specified event name(s).
157165

158-
- `eventNames` is a comma delimited string containing the names of the events the specified listener listens to.
159-
- _Optional_: The `callback` parameter points to a specific listener to be removed. If not defined, all listeners for the event names will be removed.
160-
<!-- Is the following definition correct -->
161-
- _Optional_: `thisArg` is a parameter used as `this` context in which the listener to be removed will be searched.
166+
- `eventNames`: Comma delimited string containing the names of the events the specified listener listens to.
167+
- `callback`: A specific listener to be removed. If not defined, all listeners for the event names will be removed.
168+
- `target`: Subscriber (target) of the event listener. It will be used as a thisArg in the handler function.
162169

163170
---
164171

0 commit comments

Comments
 (0)