o-spreadsheet icon indicating copy to clipboard operation
o-spreadsheet copied to clipboard

[POC] stores: bye bye reactivity 👋

Open LucasLefevre opened this issue 10 months ago • 1 comments

Description:

description of this task, what is implemented and why it is implemented that way.

Task: : TASK_ID

review checklist

  • [ ] feature is organized in plugin, or UI components
  • [ ] support of duplicate sheet (deep copy)
  • [ ] in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • [ ] in model/UI: ranges are strings (to show the user)
  • [ ] undo-able commands (uses this.history.update)
  • [ ] multiuser-able commands (has inverse commands and transformations where needed)
  • [ ] new/updated/removed commands are documented
  • [ ] exportable in excel
  • [ ] translations (_t("qmsdf %s", abc))
  • [ ] unit tested
  • [ ] clean commented code
  • [ ] track breaking changes
  • [ ] doc is rebuild (npm run doc)
  • [ ] status is correct in Odoo

LucasLefevre avatar Apr 19 '24 15:04 LucasLefevre

Could be the occasion to get rid of "RENDER_CANVAS" command then since we have a new bus to work with?

diff --git a/src/components/helpers/highlight_hook.ts b/src/components/helpers/highlight_hook.ts
index 7c0edb7e0..4fb2116f5 100644
--- a/src/components/helpers/highlight_hook.ts
+++ b/src/components/helpers/highlight_hook.ts
@@ -1,12 +1,12 @@
-import { onMounted, useEffect, useEnv } from "@odoo/owl";
-import { useLocalStore } from "../../store_engine";
+import { onMounted, useEffect } from "@odoo/owl";
+import { useLocalStore, useStoreProvider } from "../../store_engine";
 import { HighlightProvider, HighlightStore } from "../../stores/highlight_store";
-import { Ref, SpreadsheetChildEnv } from "../../types";
+import { Ref } from "../../types";
 import { useHoveredElement } from "./listener_hook";
 
 export function useHighlightsOnHover(ref: Ref<HTMLElement>, highlightProvider: HighlightProvider) {
   const hoverState = useHoveredElement(ref);
-  const env = useEnv() as SpreadsheetChildEnv;
+  const stores = useStoreProvider();
 
   useHighlights({
     get highlights() {
@@ -15,7 +15,7 @@ export function useHighlightsOnHover(ref: Ref<HTMLElement>, highlightProvider: H
   });
   useEffect(
     () => {
-      env.model.dispatch("RENDER_CANVAS");
+      stores.trigger("store-updated");
     },
     () => [hoverState.hovered]
   );
``` @LucasLefevre WDYT?

rrahir avatar May 21 '24 08:05 rrahir

@rrahir true. I pushed a commit :)

LucasLefevre avatar May 21 '24 08:05 LucasLefevre

I think it is a fantastic idea. good job !

VincentSchippefilt avatar May 21 '24 12:05 VincentSchippefilt

what would be less error prone:

class MyStore extends Store {
 constructor() {...}
 static mutators = ["myMytator","myOtherMutator"]
 myMutator(value) { ... }
 myOtherMutator(value) { ... }
 myGetter() { return value; }
}

or

class MyStore extends Store {
 constructor() {...}
 mutators : {
    myMutator = function (value) { ... },
    myOtherMutator = function (value) { ... }
 }
 myGetter() { return value; } // if I write this.mutators.myMutator here, it's obviously a bug
}

VincentSchippefilt avatar May 22 '24 07:05 VincentSchippefilt

@robodoo r+

rrahir avatar May 22 '24 08:05 rrahir