<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: beeawesome</title>
    <description>The latest articles on DEV Community by beeawesome (@beeawesome).</description>
    <link>https://dev.to/beeawesome</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F904841%2F1c080149-138b-43c3-bcb5-9a7fed492788.png</url>
      <title>DEV Community: beeawesome</title>
      <link>https://dev.to/beeawesome</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/beeawesome"/>
    <language>en</language>
    <item>
      <title>How to make 3 composable function "communicate" with each other</title>
      <dc:creator>beeawesome</dc:creator>
      <pubDate>Sun, 07 Aug 2022 15:18:40 +0000</pubDate>
      <link>https://dev.to/beeawesome/how-to-make-3-composable-function-communicate-with-each-other-42n9</link>
      <guid>https://dev.to/beeawesome/how-to-make-3-composable-function-communicate-with-each-other-42n9</guid>
      <description>&lt;p&gt;Hi devs! &lt;br&gt;
I am trying to do something simple with Vue.js and not sure if my approach is ok. &lt;br&gt;
So.. I'm trying to make 3 composable functions to "communicate". &lt;br&gt;
I'm just not sure how.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default useServer = (serverSettings) =&amp;gt; {
    let connect = () =&amp;gt; {...}
    let write = (command) =&amp;gt; {
        // Gets a command from the users GUI @click
        // then passes it to the gateway.write(command)
    }
    let read = (data) =&amp;gt; {
        // gets data from the gateway and prints data. 
    }
}

export default useDevice = (deviceSettings) =&amp;gt; {
    let connect = () =&amp;gt; {...}
    let write = (command) =&amp;gt; {
        // executes command on device
    }
    let read = (data) =&amp;gt; {
        // reads data from the device. 
    }
}

export default useGateway = (gwSettings, device, server) =&amp;gt; {
    let connect = () =&amp;gt; {...}
    let write = (command) =&amp;gt; {
        // passes the command to the device write() method
    }
    let read = () =&amp;gt; {
        // reads the data from the device and send it to the server
    }
}

let server = useServer(serverSettings)
let device = useDevice(deviceSettings)
let gateway = useGateway(gwSettings, device, server)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;im not sure how to apply event listeners for this case. Since these are variables and not events. &lt;br&gt;
I thought of using the &lt;code&gt;watch&lt;/code&gt; api for the read/write variables, instead of the current methods.&lt;br&gt;
example: inside the &lt;code&gt;useGateway()&lt;/code&gt; composables, to have some kind of a watcher:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// note: the `write` variable should be changes to a regular variable and not a method

watch(
  () =&amp;gt; server.write, // &amp;lt;-- watch this
  read // &amp;lt;-- trigger this
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>vue</category>
      <category>composable</category>
    </item>
  </channel>
</rss>
