From 3c2a34a2b4097ab07fd1fa32348963dd24d0c80b Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Fri, 18 Nov 2022 19:15:55 -0800 Subject: [PATCH] Update state template --- pynecone/.templates/web/utils/state.js | 6 +++++- pynecone/compiler/compiler.py | 2 +- pynecone/compiler/templates.py | 7 +++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pynecone/.templates/web/utils/state.js b/pynecone/.templates/web/utils/state.js index eca26bfdc..5ec5332fc 100644 --- a/pynecone/.templates/web/utils/state.js +++ b/pynecone/.templates/web/utils/state.js @@ -86,8 +86,12 @@ export const updateState = async ( router ); setResult({ + ...result, state: state, events: events, - processing: true, }); }; + +export const E = (name, payload) => { + return { name, payload }; +}; diff --git a/pynecone/compiler/compiler.py b/pynecone/compiler/compiler.py index 5d50fb749..36ee36b1e 100644 --- a/pynecone/compiler/compiler.py +++ b/pynecone/compiler/compiler.py @@ -12,7 +12,7 @@ from pynecone.state import State DEFAULT_IMPORTS: ImportDict = { "react": {"useEffect", "useState"}, "next/router": {"useRouter"}, - f"/{constants.STATE_PATH}": {"updateState"}, + f"/{constants.STATE_PATH}": {"updateState", "E"}, } diff --git a/pynecone/compiler/templates.py b/pynecone/compiler/templates.py index d509a1f4d..48a27a1ae 100644 --- a/pynecone/compiler/templates.py +++ b/pynecone/compiler/templates.py @@ -123,7 +123,6 @@ def format_state( EVENT_ENDPOINT = constants.Endpoint.EVENT.name EVENT_FN = join( [ - "const E = (name, payload) => {{ return {{name, payload}} }}", "const Event = events => {set_state}({{", " ...{state},", " events: [...{state}.events, ...events],", @@ -163,9 +162,9 @@ USE_EFFECT = join( f" events: [...{{state}}.{EVENTS}, ...{RESULT}.{EVENTS}],", " }})", f" {SET_RESULT}({{{{", - f" ...{RESULT},", - f" {{state}}: null,", - f" {PROCESSING}: false,", + f" {STATE}: null,", + f" {EVENTS}: [],", + f" {PROCESSING}: false,", " }})", " }}", f" await updateState({{state}}, {RESULT}, {SET_RESULT}, {EVENT_ENDPOINT}, {ROUTER})",