-
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.
Make accessing other components from get_extra_context_data() easier
BACKWARD INCOMPATIBLE CHANGES - Modify get_extra_context_data() to accept an instance of ExtraContextRequest(). This instance includes the component state, component_kwargs, current request, component state address, and the state manager. By including the state manager and address, it becomes possible to access stores for other components. - Remove the passing of component kwargs to init_state() and update_state(). These kwargs are redundant since both InitStateContext and UpdateStateContext already have them. - Update the example project to reflect these changes. - Add StatelessLiveComponent as a base class for components that do not need to store state.
- Loading branch information
Showing
15 changed files
with
164 additions
and
116 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
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,20 +1,12 @@ | ||
from django_components import component | ||
from pydantic import BaseModel | ||
|
||
from livecomponents import CallContext, InitStateContext, LiveComponent, command | ||
|
||
|
||
class SearchState(BaseModel): | ||
pass | ||
from livecomponents import CallContext, StatelessLiveComponent, command | ||
|
||
|
||
@component.register("coffee/search") | ||
class SearchComponent(LiveComponent[SearchState]): | ||
class SearchComponent(StatelessLiveComponent): | ||
template_name = "coffee/search/search.html" | ||
|
||
def init_state(self, context: InitStateContext, **component_kwargs) -> SearchState: | ||
return SearchState(**component_kwargs) | ||
|
||
@command | ||
def update_search(self, call_context: CallContext[SearchState], search: str): | ||
def update_search(self, call_context: CallContext, search: str): | ||
call_context.parent.update_search(search=search) |
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
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,29 +1,12 @@ | ||
from typing import Any | ||
|
||
from django_components import component | ||
from pydantic import BaseModel | ||
|
||
from livecomponents import CallContext, InitStateContext, LiveComponent, command | ||
|
||
|
||
class EmailSenderState(BaseModel): | ||
pass | ||
from livecomponents import CallContext, StatelessLiveComponent, command | ||
|
||
|
||
@component.register("emailsender") | ||
class EmailSender(LiveComponent[EmailSenderState]): | ||
class EmailSender(StatelessLiveComponent): | ||
template_name = "emailsender/emailsender.html" | ||
|
||
def get_extra_context_data( | ||
self, state: EmailSenderState, **component_kwargs | ||
) -> dict[str, Any]: | ||
return {} | ||
|
||
def init_state( | ||
self, context: InitStateContext, **component_kwargs | ||
) -> EmailSenderState: | ||
return EmailSenderState() | ||
|
||
@command | ||
def send_email(self, call_context: CallContext[EmailSenderState], email: str): | ||
def send_email(self, call_context: CallContext, email: str): | ||
print("Sending email to", email) |
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,14 +1,23 @@ | ||
from livecomponents.component import LiveComponent, command | ||
from livecomponents.component import ( | ||
ExtraContextRequest, | ||
LiveComponent, | ||
StatelessLiveComponent, | ||
command, | ||
) | ||
from livecomponents.manager.manager import ( | ||
CallContext, | ||
InitStateContext, | ||
UpdateStateContext, | ||
) | ||
from livecomponents.utils import LiveComponentsModel | ||
|
||
__all__ = [ | ||
"LiveComponent", | ||
"command", | ||
"CallContext", | ||
"InitStateContext", | ||
"UpdateStateContext", | ||
"ExtraContextRequest", | ||
"LiveComponent", | ||
"LiveComponentsModel", | ||
"StatelessLiveComponent", | ||
] |
Oops, something went wrong.