import { Observable } from 'rxjs-lite'
class ChatModelObservable extends Observable {
private messages: string[] = []
constructor() {
super()
}
sendMessage(userID: number, message: string) {
this.messages.push(message)
this._next({ userID, message })
}
}
type ChatMessageDto = {
userID: number
message: string
}
const testObservable = new ChatModelObservable()
const subscriptionA = testObservable.subscribe<ChatMessageDto>((message) =>
console.log('message received subscription A: ', message)
)
const subscriptionB = testObservable.subscribe<ChatMessageDto>((message) =>
console.log('message received subscription B: ', message)
)
testObservable.sendMessage(1, 'Hello')
subscriptionA.unsubscribe()
testObservable.sendMessage(2, 'World')
-
Notifications
You must be signed in to change notification settings - Fork 0
Lightweight reactive extensions for modern JavaScript
License
machester4/rxjs-lite
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Lightweight reactive extensions for modern JavaScript