-
Notifications
You must be signed in to change notification settings - Fork 438
feat: signals implementation v1 #3963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4a0e5f7
f7f658d
0a08b45
66f885b
65fa1cb
8037a6c
7b3582f
92413fc
fcdae16
cf3bafd
b06528b
f315852
4ec0439
3c78f17
e3b6e82
2fa1693
1565a04
6fde22a
3c6aa00
1565db7
6360bb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright (c) 2023, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: MIT | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
| */ | ||
|
|
||
| export type OnUpdate = () => void; | ||
| export type Unsubscribe = () => void; | ||
|
|
||
| export interface Signal<ValueShape> { | ||
| get value(): ValueShape; | ||
| subscribe(onUpdate: OnUpdate): Unsubscribe; | ||
| } | ||
|
|
||
| export abstract class SignalBaseClass<ValueShape> implements Signal<ValueShape> { | ||
| abstract get value(): ValueShape; | ||
|
|
||
| private subscribers: Set<OnUpdate> = new Set(); | ||
|
|
||
| subscribe(onUpdate: OnUpdate) { | ||
| this.subscribers.add(onUpdate); | ||
| return () => { | ||
| this.subscribers.delete(onUpdate); | ||
| }; | ||
| } | ||
|
|
||
| protected notify() { | ||
| for (const subscriber of this.subscribers) { | ||
| subscriber(); | ||
| } | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed, I'd love for this to be moved to a new top-level
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Uh oh!
There was an error while loading. Please reload this page.