Skip to content
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

[Local fork] TC 39 decorators #3790

Merged
merged 21 commits into from
Nov 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added class decorator
mweststrate committed Nov 6, 2023
commit 2ec64abeeb361d730610c99aa33ef352861ac5d8
7 changes: 6 additions & 1 deletion packages/mobx-react/src/observer.tsx
Original file line number Diff line number Diff line change
@@ -7,7 +7,12 @@ import { IReactComponent } from "./types/IReactComponent"
/**
* Observer function / decorator
*/
export function observer<T extends IReactComponent>(component: T): T {
export function observer<T extends IReactComponent>(component: T, context: ClassDecoratorContext): void
export function observer<T extends IReactComponent>(component: T): T
export function observer<T extends IReactComponent>(component: T, context?: ClassDecoratorContext): T {
if (context && context.kind !== "class") {
throw new Error("The @observer decorator can be used on classes only")
}
if (component["isMobxInjector"] === true) {
console.warn(
"Mobx observer: You are trying to use `observer` on a component that already has `inject`. Please apply `observer` before applying `inject`"