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
);
setResult({
...result,
state: state,
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 = {
"react": {"useEffect", "useState"},
"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_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})",