-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- DeclareState decorator now allows for passing a type safe property key config option to allow for mirroring a private state to a public variable. - Added ComponentStateRef.sync method for synchronizing two state properties to the same value.
- Loading branch information
Showing
5 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { ComponentStateMetadata } from "./metadata" | ||
|
||
/** @PropertyDecoratorFactory */ | ||
export function DeclareState(): PropertyDecorator { | ||
export function DeclareState<Name extends string = undefined>(options?: DeclareState.Options<Record<string, any>, Name> | Name) { | ||
|
||
/** @PropertyDecorator */ | ||
return function (target: any, key: string) { | ||
ComponentStateMetadata.AddManagedProperty(target.constructor, { key, async: false }); | ||
return function<ComponentT>(target: Name extends ((keyof ComponentT) | undefined) ? ComponentT : never, key: string) { | ||
const publicKey = typeof options === "string" ? options : options?.name; | ||
|
||
ComponentStateMetadata.AddManagedProperty(target.constructor, { key, publicKey, async: false }); | ||
} | ||
} | ||
|
||
export namespace DeclareState { | ||
|
||
export interface Options<ComponentT, K extends keyof ComponentT = keyof ComponentT> { | ||
name: K; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters