Update state template

This commit is contained in:
Nikhil Rao 2022-11-18 19:15:55 -08:00
parent 6bb0944ed5
commit 3c2a34a2b4
3 changed files with 9 additions and 6 deletions

View File

@ -86,8 +86,12 @@ export const updateState = async (
router router
); );
setResult({ setResult({
...result,
state: state, state: state,
events: events, events: events,
processing: true,
}); });
}; };
export const E = (name, payload) => {
return { name, payload };
};

View File

@ -12,7 +12,7 @@ from pynecone.state import State
DEFAULT_IMPORTS: ImportDict = { DEFAULT_IMPORTS: ImportDict = {
"react": {"useEffect", "useState"}, "react": {"useEffect", "useState"},
"next/router": {"useRouter"}, "next/router": {"useRouter"},
f"/{constants.STATE_PATH}": {"updateState"}, f"/{constants.STATE_PATH}": {"updateState", "E"},
} }

View File

@ -123,7 +123,6 @@ def format_state(
EVENT_ENDPOINT = constants.Endpoint.EVENT.name EVENT_ENDPOINT = constants.Endpoint.EVENT.name
EVENT_FN = join( EVENT_FN = join(
[ [
"const E = (name, payload) => {{ return {{name, payload}} }}",
"const Event = events => {set_state}({{", "const Event = events => {set_state}({{",
" ...{state},", " ...{state},",
" events: [...{state}.events, ...events],", " events: [...{state}.events, ...events],",
@ -163,9 +162,9 @@ USE_EFFECT = join(
f" events: [...{{state}}.{EVENTS}, ...{RESULT}.{EVENTS}],", f" events: [...{{state}}.{EVENTS}, ...{RESULT}.{EVENTS}],",
" }})", " }})",
f" {SET_RESULT}({{{{", f" {SET_RESULT}({{{{",
f" ...{RESULT},", f" {STATE}: null,",
f" {{state}}: null,", f" {EVENTS}: [],",
f" {PROCESSING}: false,", f" {PROCESSING}: false,",
" }})", " }})",
" }}", " }}",
f" await updateState({{state}}, {RESULT}, {SET_RESULT}, {EVENT_ENDPOINT}, {ROUTER})", f" await updateState({{state}}, {RESULT}, {SET_RESULT}, {EVENT_ENDPOINT}, {ROUTER})",