1
0
Эх сурвалжийг харах

feat(backround): pass previous block data

Ahmad Kholid 4 жил өмнө
parent
commit
88cce22526

+ 5 - 2
src/background/blocks-handler.js

@@ -11,7 +11,7 @@ export function trigger(block) {
   return new Promise((resolve) => {
     const nextBlockId = getBlockConnection(block);
 
-    resolve({ nextBlockId });
+    resolve({ nextBlockId, data: '' });
   });
 }
 
@@ -34,7 +34,10 @@ export function openWebsite(block) {
               .then(() => {
                 this._connectTab(tabId);
 
-                resolve({ nextBlockId: getBlockConnection(block) });
+                resolve({
+                  nextBlockId: getBlockConnection(block),
+                  data: block.data.url,
+                });
               });
           }
         };

+ 4 - 4
src/background/workflow-engine.js

@@ -47,18 +47,18 @@ class WorkflowEngine {
     this.isDestroyed = true;
   }
 
-  _blockHandler(block) {
+  _blockHandler(block, prevBlockData) {
     if (this.isDestroyed) return;
 
     console.log(`${block.name}(${toCamelCase(block.name)}):`, block);
     const handler = blocksHandler[toCamelCase(block?.name)];
-    /* pass data from prev block */
+
     if (handler) {
       handler
-        .call(this, block)
+        .call(this, block, prevBlockData)
         .then((result) => {
           if (result.nextBlockId) {
-            this._blockHandler(this.blocks[result.nextBlockId]);
+            this._blockHandler(this.blocks[result.nextBlockId], result.data);
           } else {
             console.log('Done');
           }