Browse Source

Update state template

Nikhil Rao 2 năm trước cách đây
mục cha
commit
3c2a34a2b4

+ 5 - 1
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 };
+};

+ 1 - 1
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"},
 }
 
 

+ 3 - 4
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})",