pass constants via js consts to state.js
This commit is contained in:
parent
c26d626bf2
commit
f163d41563
@ -23,6 +23,8 @@ export const clientStorage = {{ client_storage|json_dumps }}
|
|||||||
export const clientStorage = {}
|
export const clientStorage = {}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
export const main_state_name = "{{const.main_state_name}}"
|
||||||
|
export const update_vars_internal = "{{const.update_vars_internal}}"
|
||||||
{% if state_name %}
|
{% if state_name %}
|
||||||
export const state_name = "{{state_name}}"
|
export const state_name = "{{state_name}}"
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ import {
|
|||||||
onLoadInternalEvent,
|
onLoadInternalEvent,
|
||||||
state_name,
|
state_name,
|
||||||
exception_state_name,
|
exception_state_name,
|
||||||
|
main_state_name,
|
||||||
|
update_vars_internal,
|
||||||
} from "$/utils/context.js";
|
} from "$/utils/context.js";
|
||||||
import debounce from "$/utils/helpers/debounce";
|
import debounce from "$/utils/helpers/debounce";
|
||||||
import throttle from "$/utils/helpers/throttle";
|
import throttle from "$/utils/helpers/throttle";
|
||||||
@ -810,7 +812,7 @@ export const useEventLoop = (
|
|||||||
const vars = {};
|
const vars = {};
|
||||||
vars[storage_to_state_map[e.key]] = e.newValue;
|
vars[storage_to_state_map[e.key]] = e.newValue;
|
||||||
const event = Event(
|
const event = Event(
|
||||||
`${state_name}.{{ update_vars_internal }}`,
|
`${state_name}.${update_vars_internal}`,
|
||||||
{ vars: vars }
|
{ vars: vars }
|
||||||
);
|
);
|
||||||
addEvents([event], e);
|
addEvents([event], e);
|
||||||
@ -824,7 +826,7 @@ export const useEventLoop = (
|
|||||||
// Route after the initial page hydration.
|
// Route after the initial page hydration.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const change_start = () => {
|
const change_start = () => {
|
||||||
const main_state_dispatch = dispatch["state"];
|
const main_state_dispatch = dispatch[main_state_name];
|
||||||
if (main_state_dispatch !== undefined) {
|
if (main_state_dispatch !== undefined) {
|
||||||
main_state_dispatch({ is_hydrated: false });
|
main_state_dispatch({ is_hydrated: false });
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ class ReflexJinjaEnvironment(Environment):
|
|||||||
from reflex.state import (
|
from reflex.state import (
|
||||||
FrontendEventExceptionState,
|
FrontendEventExceptionState,
|
||||||
OnLoadInternalState,
|
OnLoadInternalState,
|
||||||
|
State,
|
||||||
UpdateVarsInternalState,
|
UpdateVarsInternalState,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ class ReflexJinjaEnvironment(Environment):
|
|||||||
"set_color_mode": constants.ColorMode.SET,
|
"set_color_mode": constants.ColorMode.SET,
|
||||||
"use_color_mode": constants.ColorMode.USE,
|
"use_color_mode": constants.ColorMode.USE,
|
||||||
"hydrate": constants.CompileVars.HYDRATE,
|
"hydrate": constants.CompileVars.HYDRATE,
|
||||||
|
"main_state_name": State.get_name(),
|
||||||
"on_load_internal": f"{OnLoadInternalState.get_name()}.on_load_internal",
|
"on_load_internal": f"{OnLoadInternalState.get_name()}.on_load_internal",
|
||||||
"update_vars_internal": f"{UpdateVarsInternalState.get_name()}.update_vars_internal",
|
"update_vars_internal": f"{UpdateVarsInternalState.get_name()}.update_vars_internal",
|
||||||
"frontend_exception_state": FrontendEventExceptionState.get_full_name(),
|
"frontend_exception_state": FrontendEventExceptionState.get_full_name(),
|
||||||
|
Loading…
Reference in New Issue
Block a user