<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Onur Köse on Medium]]></title>
        <description><![CDATA[Stories by Onur Köse on Medium]]></description>
        <link>https://medium.com/@onur-kose?source=rss-2553eefe2f32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JYwGYKD_3mUoyULBGDUfhQ.jpeg</url>
            <title>Stories by Onur Köse on Medium</title>
            <link>https://medium.com/@onur-kose?source=rss-2553eefe2f32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:16:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@onur-kose/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Connecting API Platform with Supabase for Local Development]]></title>
            <link>https://onur-kose.medium.com/connecting-api-platform-with-supabase-for-local-development-fc80561f39dc?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc80561f39dc</guid>
            <category><![CDATA[api-platform]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Fri, 23 May 2025 16:25:07 GMT</pubDate>
            <atom:updated>2025-05-23T16:25:07.408Z</atom:updated>
            <content:encoded><![CDATA[<p>When you install the API Platform backend on your local computer with Docker, it comes with a PostgreSQL container. If you’re using Supabase Database in your Staging and Production environments, this situation can become somewhat problematic for local development. Supabase has released a package through Homebrew to provide a local development environment on macOS. Using this package, we can install all Supabase services with Docker through just a single command. Now the only remaining problem is how the API Platform PHP container will communicate with the Supabase DB container instead of its own PostgreSQL container. To establish this communication, we need to create a communication bridge between the two containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*VzIcGgZfWfChwJz1s1SrIg.png" /></figure><p>First, we copy the connection parameters by clicking the Connect button in the Supabase Dashboard, and we need to replace the default parameters in the DATABASE_URL environment variable in API Platform’s compose.override.yaml file with these.</p><p>At this point, you may want to export the API Platform database to back it up and import it into the Supabase database. This way, you can continue using the database from where you left off without dealing with Migration or Seed.</p><p>Then, while in the root folder of your API Platform project, we should terminate the containers with the docker-compose down command. Next, we find the network name used by the Supabase containers with the docker network ls command. It should typically be a network name starting with supabase_network. After finding this, we define the network in compose.override.yaml so that the PHP container can be included in this network.</p><pre>services:<br>  php:<br>    ...<br>    networks:<br>      - supabase-shared<br><br>  pwa:<br>    ...<br>    networks:<br>      - supabase-shared<br><br>networks:<br>  supabase-shared:<br>    external: true<br>    name: supabase_network_...</pre><p>Now we’re ready to recreate the containers:</p><pre>docker-compose build --no-cache<br>docker-compose up -d</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc80561f39dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Delete Multiple Records in GraphQL]]></title>
            <link>https://javascript.plainenglish.io/how-to-delete-multiple-records-in-graphql-ed76103e77de?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed76103e77de</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Sun, 02 May 2021 18:12:02 GMT</pubDate>
            <atom:updated>2021-05-07T06:54:50.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J35-nx4hUD-eMUMR" /><figcaption>Photo by <a href="https://unsplash.com/@ujesh?utm_source=medium&amp;utm_medium=referral">u j e s h</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I used a very <a href="https://medium.com/novvum/graphql-code-first-and-sdl-first-the-current-landscape-in-mid-2019-699f68b31a65">SDL-first</a> approach with this GraphQL server of my side hustle project, and I decided to switch to <a href="https://api-platform.com/docs/core/graphql/">API Platform</a> after a couple of days of development with some other framework.</p><p>It allows all CRUD operations to be ready when you are sure of your resources, and it’s fantastic in this way. But I didn’t want to rewrite some of them just to get it to fit some more functional requirements.</p><p>One of them is bulk-deleting records from a data-table like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*ljSyyH4n3sVfRf7z5enkWA.png" /></figure><p>I am using the Composition API of Vue Apollo, and it deletes a single record with this:</p><pre>const { mutate: someDeleteMutationCaller } = useMutation(gql`<br>  mutation deleteMyRecordMutation ($id: ID!) {<br>    deleteMyRecord (input: {id: $id}) {<br>      myRecord {<br>        id<br>      }<br>    }<br>  }`);</pre><pre>someDeleteMutation({id: &quot;id of the myRecord item&quot;});</pre><p>But if I want to delete more than one record at a time, this logic will not help me.</p><p>Here is why:</p><p>The first and very bad option is to call the mutation multiple times:</p><pre>someDeleteMutationCaller({id: &quot;/my_record/1&quot;});<br>someDeleteMutationCaller({id: &quot;/my_record/2&quot;});<br>someDeleteMutationCaller({id: &quot;/my_record/3&quot;});<br>...<br>someDeleteMutationCaller({id: &quot;/my_record/100&quot;});</pre><p>But as you can see, this approach is not efficient and it’s possible to hit rate-limiting.</p><p>Another option is to send an array of IDs, instead of a single ID:</p><pre>const { mutate: someDeleteMutationCaller } = useMutation(gql`<br>  mutation deleteMyRecordsMutation ($ids: [ID]!) {<br>    deleteMyRecords (input: {ids: $ids}) {<br>      myRecord {<br>        id<br>      }<br>    }<br>  }`);</pre><pre>someDeleteMutationCaller({ids: [&quot;/my_record/1&quot;, &quot;/my_record/2&quot;, &quot;/my_record/3&quot;]});</pre><p>To make this work, you should either modify the original/native <em>delete</em> operation of your framework or add another one to handle multiple deletes and keep the original delete operation to handle single deletes.</p><p>A better option is to make your mutation query handles multiple deletes.</p><pre>const { mutate: someDeleteMutationCaller } = useMutation(gql`<br>  mutation deleteMyRecordMutation {<br>    id_1: deleteMyRecord (input: {id: &quot;/my_record/1&quot;}) {<br>      myRecord {<br>        id<br>      }<br>    }</pre><pre>    id_2: deleteMyRecord (input: {id: &quot;/my_record/2&quot;}) {<br>      myRecord {<br>        id<br>      }<br>    }<br>        <br>    id_3: deleteMyRecord (input: {id: &quot;/my_record/3&quot;}) {<br>      myRecord {<br>        id<br>      }<br>    }<br>  }`);</pre><pre>someDeleteMutationCaller();</pre><p>The problem with this approach is that we are no longer able to use variables to pass to our query because the mutation call must repeat itself per record ID. Also, we cannot call useMutation method outside of setup function of Vue.js. <a href="https://github.com/vuejs/vue-apollo/issues/1145">It just doesn’t work</a> at the time I write this.</p><p>Since we are using mighty Vue.js, we can of course overcome this problem:</p><pre>setup() {<br>  const deleteMyRecordsMutationContext = ref([]);<br>  <br>  const { mutate: someDeleteMutation } = useMutation(() =&gt; {<br>    return gql`<br>      mutation deleteMyRecordMutation {<br>        ${deleteMyRecordsMutationContext.value.join(&#39;\n&#39;)}<br>      }`<br>    });</pre><pre>return {<br>    deleteMutationCaller () {<br>      const myObjectIDsToDelete = [<br>        {_id: 1, id: &quot;/my_record/1&quot;},<br>        {_id: 2, id: &quot;/my_record/2&quot;},<br>        {_id: 3, id: &quot;/my_record/3&quot;},<br>        ...,<br>        {_id: 100, id: &quot;/my_record/100&quot;}<br>      ];<br><br>      deleteMyRecordsMutationContext.value = myObjectIDsToDelete.map((item) =&gt; {<br>        <em>return</em> `<br>          id_${item._id}: deleteMyRecord(input: {id: &quot;${item.id}&quot;}) {<br>            myRecord {<br>              id<br>            }<br>          }`<br>      });</pre><pre>      someDeleteMutation();<br>    }<br>  } <br>}</pre><p>Now the context of the mutation query will be generated automatically, and you’ll be able to delete all the records within the array without changing a single line of backend code.</p><p>The trick here is to use a function call instead of putting the <em>gql</em> call directly into <em>useMutation</em>.</p><p>I hope this helps someone. Thank you for reading.</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed76103e77de" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-delete-multiple-records-in-graphql-ed76103e77de">How to Delete Multiple Records in GraphQL</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue.js Password Generator]]></title>
            <link>https://medium.com/js-dojo/vue-js-password-generator-7a70394bdba9?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a70394bdba9</guid>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[ui-ux]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[quasarframework]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Sun, 22 Mar 2020 08:09:13 GMT</pubDate>
            <atom:updated>2020-03-25T06:08:32.504Z</atom:updated>
            <content:encoded><![CDATA[<p>I would like to share my latest fancy password generator with you.</p><p>It will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*X1MS6qq1uKXYxYOZiNJs0w.png" /></figure><p>Its features are basically;</p><ol><li>Password strength slider with other form components via <a href="https://quasar.dev/vue-components/input">Quasar Framework</a>.</li><li>Password fields can be masked/unmasked, so there’s no need an additional check password field.</li><li>Has fingerprint display as a strengthometer, thanks to <a href="https://github.com/Akryum/vue-progress-path">Akryum/vue-progress-path</a>.</li><li>Generated password field has “copy to clipboard” and “move itself to new password field” button.</li></ol><p>I should skip how to create first two current/new password fields, those instructions are well documented <a href="https://quasar.dev/vue-components/input#Input-types">here</a>.</p><p>Generated password field is also very simple;</p><pre>&lt;q-input<br>  readonly<br>  stack-label<br>  type=&quot;text&quot;<br>  autocomplete=&quot;off&quot;<br>  v-model=&quot;generatedPassword&quot;<br>  label=&quot;Generated password&quot;<br>&gt;<br>  &lt;template v-slot:after&gt;<br>    &lt;q-btn round flat dense icon=&quot;mdi-clipboard-arrow-up-outline&quot; @click=&quot;copyGeneratedPassword&quot; /&gt;<br>  &lt;/template&gt;<br>&lt;/q-input&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*NxKZNZYTtF9NM9d6UErftg.gif" /><figcaption>How the copy to clipboard button works</figcaption></figure><p><em>copyGeneratedPassword</em> method is like this:</p><pre><em>import</em> { copyToClipboard } <em>from</em> &#39;quasar&#39;<br>...</pre><pre>data: {<br>  newPassword: &#39;&#39;<br>},</pre><pre>methods: {<br>  copyGeneratedPassword () {<br>    this.newPassword = this.generatedPassword<br>  <br>    copyToClipboard(this.generatedPassword)<br>  <br>    this.$q.notify({<br>      progress: true,<br>      type: &#39;positive&#39;,<br>      message: `Generated password has been copied to clipboard.`<br>    })<br>  }<br>}</pre><p>This method basically copies <em>generatedPassword</em> to clipboard as well as on to the <em>newPassword </em>(<em>generatedPassword</em> here is a computed property and described below).</p><p><em>this.$q.notify</em> is another Quasar plugin, described <a href="https://quasar.dev/quasar-plugins/notify">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*bGFsNax7rp5nRL9PF2gHcw.gif" /><figcaption>Notification plugin</figcaption></figure><p>Also the <em>copyToClipboard</em> helper comes from Quasar <a href="https://quasar.dev/quasar-utils/other-utils">utils</a>. I like using Quasar so much.</p><p>Now it’s time for the slider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*o_sdn01uQp4xADoRvTj6Bw.gif" /></figure><pre>&lt;q-item&gt;<br>  &lt;q-item-section&gt;<br>    &lt;q-slider<br>      snap<br>      label<br>      markers<br>      :step=&quot;12&quot;<br>      :min=&quot;0&quot;<br>      :max=&quot;48&quot;<br>      :color=&quot;strengthColor&quot;<br>      :label-value=&quot;strengthLabel&quot;<br>      v-model=&quot;strengthLevel&quot;<br>    /&gt;<br>  &lt;/q-item-section&gt;</pre><pre>  &lt;q-item-section avatar&gt;<br>    &lt;loading-progress<br>      :progress=&quot;strengthLevel / 100&quot;<br>      shape=&quot;M23,3.1c-3.1-1.6-5.8-2.3-9.1-2.3c-3.2,0-6.3,0.8-9.1,2.3 M27.1,11c-1.5-2.1-3.3-3.7-5.5-4.8 c-4.7-2.4-10.7-2.4-15.3,0C4,7.4,2.2,9,0.7,11 M22.2,18.7c0-4.3-3.7-7.8-8.2-7.8s-8.2,3.5-8.2,7.8c0,2.5,0.6,4.9,1.6,6.8 c1.1,2.1,1.9,2.9,3.3,4.3 M22.6,27.4c-1.9,0-3.7-0.5-5.1-1.5c-2.4-1.6-3.9-4.3-3.9-7.2 M18.5,30.8c-2.6-0.8-4.3-1.7-6.1-3.5 c-2.3-2.3-3.5-5.3-3.5-8.5c0-2.6,2.3-4.8,5-4.8s5,2.2,5,4.8c0,1.7,1.5,3.2,3.4,3.2c1.9,0,3.4-1.4,3.4-3.2c0-6.1-5.3-11.1-11.8-11.1 c-4.6,0-8.9,2.6-10.8,6.6c-0.6,1.3-1,2.9-1,4.6c0,1.3,0.1,3.3,1.1,5.9&quot;<br>      fill-duration=&quot;2&quot;<br>      height=&quot;32&quot;<br>      width=&quot;30&quot;<br>      size=&quot;32&quot;<br>    /&gt;<br>  &lt;/q-item-section&gt;<br>&lt;/q-item&gt;</pre><p>While the client slides right or left, <em>strengthLevel</em> changes from 0 to 48 ( I will explain why 48 is the maximum number here later). <em>strengthColor</em> and <em>strengthLabel</em> are computed properties are bound to <em>strengthLevel</em>.</p><p>LoadingProgress component here is actually <a href="https://github.com/Akryum/vue-progress-path">Akryum/vue-progress-path</a> with my custom fingerprint SVG. It’s not originally made for this purpose here but combination with QSlider works well, and also explains why I used 48 for the maximum value of QSlider. The length of the SVG determines the maximum number.</p><p>Now here are the computed properties:</p><pre>data: {<br>  strengthLevel: 24 // default strength level on pageLoad<br>},</pre><pre>computed: {<br>  generatedPassword () {<br>    let charactersArray = &#39;a-z&#39;.split(&#39;,&#39;)<br>    let CharacterSet = &#39;&#39;<br>    let password = &#39;&#39;<br>    let size = 8<br>    <br>    <em>switch</em> (this.strengthLevel) {<br>      <em>case</em> 12:<br>        size = 10<br>        charactersArray = &#39;a-z,A-Z&#39;.split(&#39;,&#39;)<br>        <em>break</em></pre><pre><em>      case</em> 24:<br>        size = 12<br>        charactersArray = &#39;a-z,A-Z,0-9&#39;.split(&#39;,&#39;)<br>        <em>break</em></pre><pre><em>     case</em> 36:<br>        size = 14<br>        charactersArray = &#39;a-z,A-Z,0-9,#&#39;.split(&#39;,&#39;)<br>        <em>break</em></pre><pre><em>     case</em> 48:<br>        size = 16<br>        charactersArray = &#39;a-z,A-Z,0-9,#&#39;.split(&#39;,&#39;)<br>        <em>break<br>    </em>}</pre><pre><em>    if</em> (charactersArray.indexOf(&#39;a-z&#39;) &gt;= 0) {<br>      CharacterSet += &#39;abcdefghijklmnopqrstuvwxyz&#39;<br>    }</pre><pre><em>    if</em> (charactersArray.indexOf(&#39;A-Z&#39;) &gt;= 0) {<br>      CharacterSet += &#39;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#39;<br>    }<br>    <br>    <em>if</em> (charactersArray.indexOf(&#39;0-9&#39;) &gt;= 0) {<br>      CharacterSet += &#39;0123456789&#39;<br>    }</pre><pre><em>    if</em> (charactersArray.indexOf(&#39;#&#39;) &gt;= 0) {<br>      CharacterSet += &#39;![]{}()%&amp;*$#^&lt;&gt;~@|&#39;<br>    }</pre><pre><em>    for</em> (let i = 0; i &lt; size; i++) {<br>      password += CharacterSet.charAt(Math.floor(Math.random() * CharacterSet.length))<br>    }<br>    <br>    <em>return</em> password<br>  },</pre><pre>  strengthLabel () {<br>    <em>switch</em> (this.strengthLevel) {<br>      <em>case</em> 12:<br>        <em>return</em> &#39;poor&#39;<br>      <em>case</em> 24:<br>        <em>return</em> &#39;fair&#39;<br>      <em>case</em> 36:<br>        <em>return</em> &#39;good&#39;<br>      <em>case</em> 48:<br>        <em>return</em> &#39;excellent&#39;<br>      <em>default</em>:<br>        <em>return</em> &#39;weak&#39;<br>    }<br>  },</pre><pre>  strengthColor () {<br>    <em>switch</em> (this.strengthLevel) {<br>      <em>case</em> 12:<br>        <em>return</em> &#39;amber-10&#39;<br>      <em>case</em> 24:<br>        <em>return</em> &#39;orange-6&#39;<br>      <em>case</em> 36:<br>        <em>return</em> &#39;primary&#39;<br>      <em>case</em> 48:<br>        <em>return</em> &#39;positive&#39;<br>      <em>default</em>:<br>        <em>return</em> &#39;blue-grey-3&#39;<br>    }<br>  }<br>}</pre><p><em>strengthColor</em> return values are from Quasar <a href="https://quasar.dev/style/color-palette">color palette</a>.</p><p>generatedPassword computed property is <a href="https://codepen.io/CSWApps/pen/QvYNMM">originally made</a> by <a href="https://codepen.io/CSWApps">Christophor Wilson</a> and I just changed a bit of it.</p><p>P.S.: One final trick for vue-progress-path styles. It has a predefined stroke-width value for the fingerprint filling action, which is pretty thick, and you can get it thinner by:</p><pre>&lt;style&gt;<br>  .vue-progress-path path {<br>    stroke-width:1 !important;<br>  }<br>&lt;/style&gt;</pre><p>That’s it! The rest of my code is the validations of the password fields and mutation mechanism on server side. I hope you enjoyed it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a70394bdba9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/js-dojo/vue-js-password-generator-7a70394bdba9">Vue.js Password Generator</a> was originally published in <a href="https://medium.com/js-dojo">Vue.js Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue-Apollo and Laravel Authentication issue]]></title>
            <link>https://onur-kose.medium.com/vue-apollo-and-laravel-authentication-issue-8736e56c4bd4?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/8736e56c4bd4</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[auth]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 09:01:17 GMT</pubDate>
            <atom:updated>2020-03-12T09:02:22.053Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vue-Apollo and Laravel Authentication Issue</h3><p>This one is really short;</p><p>I am currently working on a project which requires authentication to its API server. API server built up on Laravel and uses Airlock (can be used Passport it doesn’t matter) for API authentication.</p><p>To authenticate the GraphQL requests on API server, we use attaching <em>access token</em> to headers option, like this;</p><pre><em>import</em> { <em>ApolloClient</em> } <em>from</em> &#39;apollo-client&#39;<br><em>import</em> { <em>from</em> } <em>from</em> &#39;apollo-link&#39;<br><em>import</em> { <em>HttpLink</em> } <em>from</em> &#39;apollo-link-http&#39;<br><em>import</em> { <em>onError</em> } <em>from</em> &#39;apollo-link-error&#39;</pre><pre>const getHeaders = () =&gt; {<br>  const headers = {}<br>  const token = Vue.prototype.$token // comes from auth plugin, may also derived from session storage</pre><pre><em>  if</em> (<em>token</em>) {<br>     headers.Authorization = `Bearer ${token}`<br>  }<br>  <br>  <em>return</em> headers<br>}</pre><pre>const apolloClient = new ApolloClient({<br>   link: from([<br>      onError(errorHandler =&gt; {<br>         console.warn(errorHandler)<br>      }),<br>      new HttpLink({<br>         uri: `http://localhost/graphql`,<br>         headers: getHeaders()<br>      })<br>   ]),<br>   cache, // comes from InMemoryCache<br>   connectToDevTools: true<br>})</pre><p>The issue with this is, ApolloLinkHttp comes with two default headers:</p><pre>/node_modules/apollo-link-http-common/lib/bundle.cjs.js</pre><pre>var defaultHeaders = {<br>   accept: &#39;*/*&#39;,<br>   &#39;content-type&#39;: &#39;application/json&#39;,<br>};</pre><p>ContentType is totally fine to be here but <em>accept</em> key is a big no no for Laravel. Laravel tends to redirect user to “login” of its web ui, if detects a generic “*/*” setting on <em>accept</em> header. Therefore, if your token is expired and if you try to catch it in your interceptors, you won’t be able to do that.</p><p>To correct this, change the getHeaders function like this:</p><pre>const getHeaders = () =&gt; {<br>  const headers = {}<br>  const token = Vue.prototype.$token // comes from auth plugin</pre><pre><em>  if</em> (<em>token</em>) {<br>     headers.Authorization = `Bearer ${token}`<br>  }</pre><pre>  headers.accept = &#39;application/json&#39;</pre><pre>  <em>return</em> headers<br>}</pre><p>Another trick here, don’t write here (<em>like me</em>) “<em>headers.Accept</em>” because you’ll end up with two headers on your request, and of course Laravel still be redirecting user to login route:</p><pre><strong>accept: */*</strong><br><strong>Accept:</strong> application/json</pre><p>Laravel should now return a nice JSON with a 401 status code and you may intercept it as you wish:</p><pre>{message: “Unauthenticated.”}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8736e56c4bd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Updating Vue Apollo Store From Different Sources]]></title>
            <link>https://itnext.io/updating-vue-apollo-store-from-different-sources-6802f812e0d8?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/6802f812e0d8</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[apollo]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Tue, 10 Mar 2020 09:37:21 GMT</pubDate>
            <atom:updated>2020-03-10T20:48:51.993Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been using GraphQL since Vue-Apollo’s first release for every API development project and just like any other new working environment, Vue-Apollo has its own caveats. One of them is that you can’t simply update its own store without calling a mutation (<em>in practice, actually a Query also updates the store but that not is the case for this subject</em>).</p><p>Obviously, it’s completely logical from the developer aspect. If you’d like to keep your <a href="https://en.wikipedia.org/wiki/Single_source_of_truth">SSOT</a> concept intact, this is the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wqBlMZv1oO1JMidTrs2TZQ.gif" /></figure><p>But, and there’s always a but, there might be some occasions in which you may want to update your fetched GraphQL data (<strong><em>store</em></strong> in this context) on the client’s screen. In my case, here is the scenario:</p><ol><li>On the client side, there’s a simple input and user enters some Id numbers into the database,</li><li>On the same page, there’s a “Latest Id Numbers” list so user can see some results after submitting data,</li><li>When page loads for the first time, last 10 of Id numbers fetched with a GraphQL Query,</li><li>When user submits a new Id number, a Mutation works and updates the Query with the new data,</li><li>On the server side, a Laravel command works every minute to check if an Id number marked as “invalidated”,</li><li>There’s a 3rd party validation server for this Id numbers and this command fires a Job to send Id number data to validate,</li><li>In the meantime, to show what’s the situation about this validation process to user without refreshing it’s page or polling the GraphQL server every second I use Pusher service and that Job fires an Event to update the “Latest Id Numbers” list and the fun begins,</li><li>While the user can still be inserting new Id numbers to the database, he can still see his list feeding with the data he enters and with the data Pusher updates it.</li></ol><p>The problem with this concept is, you may update the Vue data (derived from GraphQL query) and your page will still be totally fine. On the number 8 above, Pusher sends an update through its channel, and informs about updated data:</p><pre>mounted () {<br>   this.channel = this.$pusher.subscribe(`private-User.Entries.${this.user.id}`)</pre><pre>   this.channel.bind(&#39;pusher:subscription_succeeded&#39;, (e) =&gt; {</pre><pre>      console.warn(&#39;Subscribed to Entries channel.&#39;)</pre><pre>   })</pre><pre>   this.channel.bind(&#39;App\\Events\\EntryStatus&#39;, (data) =&gt; {</pre><pre>      this.onUpdateEntry(data)</pre><pre>   })<br>}</pre><p>In this code you may see whenever EntryStatus event is fired on Laravel side, it updates the Pusher and Pusher updates my Vue app then fires onUpdateEntry method with its updated data.</p><pre>data () {<br>    return {<br>        pendingUpdates: []<br>    }<br>},</pre><pre>methods: {<br>   onUpdateEntry (entryUpdated) {<br>      // First part</pre><pre>      const entryRendered = this.$apolloData.data.entriesPaginate.find(entry =&gt; entry.id === entryUpdated.id)</pre><pre><em>     if</em> (entryRendered !== undefined) {<br>         entryRendered.status = entryUpdated.status<br>     }</pre><pre>     // Second part</pre><pre>     const index = this.pendingUpdates.findIndex(entry =&gt; entry.id === entryUpdated.id)</pre><pre><em>     if</em> (index !== -1) {<br>         this.$set(this.pendingUpdates, index, entryUpdated)<br>     } <em>else</em> {<br>         this.pendingUpdates.push(entryUpdated)<br>     }</pre><pre>}</pre><p>This code updates the rendered GraphQL data and polls the updated entry data at the same time. Notice the entryRendered object. You may wonder why would anyone needs to poll the entryUpdated data when it’s possible to update the apolloData, right? The thing is, apolloData here, is not the actual Apollo store. It’s the dataset you may change it in your Query’s result method.</p><pre>data () {<br>    return {<br>        pendingUpdates: [],<br>        loading: false,<br>        total: 0,<br>        pagination: {<br>            age: 1,<br>            rowsPerPage: 10,<br>            sortBy: &#39;id&#39;,<br>            descending: true<br>        },<br>        entriesPaginate: []<br>    }<br>},</pre><pre>apollo: {<br>    entriesPaginate: () =&gt; ({<br>        query: ENTRY_PAGINATE,<br>        context: { uri: &#39;http://localhost/graphql&#39; },<br>        variables () {<br>            <em>return</em> this.pagination<br>        },<br>        result ({ data: { entriesPaginate: { data, total } }, loading }) {<br>            <em>if</em> (!loading) {<br>                this.total = total<br>                this.entriesPaginate = data.slice().map((key, i) =&gt; ({<br>                   ...key,<br>                   __index: i<br>                }))<br>            }<br>        },<br>        watchLoading (isLoading) {<br>            this.loading = isLoading<br>        }<br>    })<br>}</pre><p>With Vue-Apollo, you may ignore the result method on your queries (and also the entriesPaginate array in data) and let the Apollo handle the assignment of query result to Vue data. But in my case, I needed the total data separately and there might be some other alterations on the data set. Therefore I use result method here. But use it or not, entriesPaginate array will be a slice of Apollo store’s original query result.</p><p>So it doesn’t matter if I update <em>this.$apolloData.data.entriesPaginate</em> or <em>this.entriesPaginate</em> in <em>onUpdateEntry</em> method. When user submits a new Id and triggers the Mutation, Apollo will trigger Query result method itself (defined or not), and this.entriesPaginate array will be updated with Apollo store’s original data. That means all the updates from <em>onUpdateEntry </em>method will be rolled back on the user’s screen. He/She will see the new Id entry and the old query’s data.</p><p>To overcome this problem, we would’ve been using an <em>this.$apollo.store</em> method, but there’s not such one. So I’ve came up with this work-around idea of polling the updated data. In <em>onUpdateEntry</em> method, you may notice there are two parts of code with comments, first and second. The second parts inserts the <em>updatedEntry</em> data into <em>pendingUpdates</em> array. I keep those records to update store first, when user submits a new Id into database via Mutation. Here it is:</p><pre>data () {<br>    return {<br>        graphQLErrors: [],<br>        form: {<br>            idNumber: null<br>        },<br>        pendingUpdates: [], // Empty here for definition, actual data filled with multiple entryUpdated data.<br>    }<br>},</pre><pre>methods: {<br>    submit () {<br>        this.loading = true</pre><pre>        this.$apollo.mutate({<br>             mutation: ENTRY_CREATE,<br>             variables: {<br>                 entry: {<br>                     id_number: this.form.idNumber<br>                 }<br>             },<br>             context: { uri: &#39;http://localhost/graphql&#39; },<br>             update: (store, { data: { entryCreated } }) =&gt; {<br>                 const query = {<br>                     query: ENTRY_PAGINATE,<br>                     variables: this.pagination<br>                 }, data = store.readQuery(query)<br>             <br>                 if (data !== undefined) {<br>                      // First part<br>                      if (this.pendingUpdates.length) {<br>                         this.pendingUpdates.forEach(entryUpdated =&gt; {<br>                             const index = data.entriesPaginate.data.findIndex(entry =&gt; entry.id === entryUpdated.id)<br>                             if (index !== -1) {<br>                                 this.$set(data.entriesPaginate.data, index, entryUpdated)<br>                             }<br>                         })</pre><pre>                         this.pendingUpdates = [] // Reset<br>                     }<br>                     <br>                     // Second part<br>                     if (data.entriesPaginate.data.findIndex(entry =&gt; entry.id === entryCreated.id) === -1) {<br>                         data.entriesPaginate.data.unshift(entryCreated)<br> <br>                         store.writeQuery({<br>                             ...query,<br>                             data: data<br>                         })<br>                     }<br>                 }<br>             }<br>        }).catch((e) =&gt; {<br>            this.graphQLErrors = e<br>        }).then(() =&gt; {<br>            this.loading = false<br>        })<br>    }<br>}</pre><p>You may notice here the <em>update</em> method of the Mutation is in two parts again. The first part, before updating the store with newly created data, iterates the <em>pendingUpdates</em> array and updates the Apollo store, then the second part inserts the <em>entryCreated</em> object at the top of the list and finally <em>store.writeQuery</em> finalizes the update.</p><p>The most important part of all above is, you have to publish the same GraphQL data to Pusher. I did not investigate if my Laravel GraphQL package capable of doing that, so I just mimic the way how GraphQL serves data. To be more clear, this is the example of GraphQL query results for <em>entriesPaginate</em>:</p><pre>{<br>  data: {<br>    entriesPaginate: [<br>      {id: 1, id_number: 12345678, created_at: SomeDate, validated_at: SomeDate, status: &quot;queued&quot;, __typename: &quot;Entry&quot;},<br>      {id: 2, id_number: 34567890, created_at: SomeDate, validated_at: SomeDate, status: &quot;validated&quot;, __typename: &quot;Entry&quot;},<br>      {id: 3, id_number: 45678901, created_at: SomeDate, validated_at: SomeDate, status: &quot;validating&quot;, __typename: &quot;Entry&quot;},<br>      ...<br>    ],<br>    total: 41,<br>    __typename: &quot;entriesPagination&quot;<br>  }<br>}</pre><p>And this my broadcating Event’s <em>broadcastWith</em> method to send data to Pusher:</p><pre>public function broadcastWith()<br>{<br>    return [<br>        &#39;__typename&#39; =&gt; &#39;Entry&#39;,<br>        &#39;id&#39; =&gt; $this-&gt;entry-&gt;id,<br>        &#39;id_number&#39; =&gt; $this-&gt;entry-&gt;id_number,<br>        &#39;status&#39; =&gt; $this-&gt;entry-&gt;status,<br>        &#39;created_at&#39; =&gt; $this-&gt;entry-&gt;created_at,<br>        &#39;validated_at&#39; =&gt; $this-&gt;entry-&gt;validated_at<br>    ];<br>}</pre><p>Keeping the data in the same format prevents Apollo store update errors.</p><p>In Vue code examples, I used the most relevant data items in data object. So please don’t try to use the code above simply copy-pasting as they may be missing data definitions/methods.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6802f812e0d8" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/updating-vue-apollo-store-from-different-sources-6802f812e0d8">Updating Vue Apollo Store From Different Sources</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Summary of a Weekend Project]]></title>
            <link>https://onur-kose.medium.com/summary-of-a-weekend-project-7eeb0354eb2a?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eeb0354eb2a</guid>
            <category><![CDATA[nativescript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[quasarframework]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Sat, 29 Dec 2018 21:33:21 GMT</pubDate>
            <atom:updated>2020-02-19T15:48:12.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*Bn5Q6FlSPxZ6yaWT5avwDQ.png" /><figcaption>image courtesy of expo web site.</figcaption></figure><p>Today I wanted to take a look at the <a href="https://www.nativescript.org/">NativeScript</a> and <a href="https://flutter.io/">Flutter</a>. It was long time ago since my last check on {NS} but Flutter was not even on my radar until today.</p><p>I’ve been working with <a href="https://vuejs.org/">Vue.js</a> and <a href="https://quasar-framework.org/">Quasar Framework</a> lately and they are doing very good job except a little performance issues on Mobile Apps. I see their fans and stars are growing each day and promising great deal.</p><p>As you may know there are couple frameworks out there in the wilderness that you can build Mobile Apps, PWAs, SPAs or simple web sites within. Only one of them was declaring that you can build a native app by writing TypeScript, Js and CSS and that (was) NativeScript. They have a new competitor named as Flutter (by Google)</p><p>What NativeScript does is basically nothing different than <a href="https://cordova.apache.org/">Cordova</a> with an extra plugin support and speed. In Cordova community, fellow dudes writes iOS and Android (and for other platforms) code for you and those codes becomes “<a href="https://cordova.apache.org/plugins/">plugins</a>” and you write your dearest JavaScript code within whatever framework inside and use those plugins when you need some device feature (then magic happens). What NativeScript people does, they simply writes almost every component as “<a href="https://docs.nativescript.org/ui/components">ui widgets</a>” for you and you still need to write some JavaScript code. But the trick is, the components are strictly bonded to their native equivalent (iOS, Android etc.) code so you have to use them as they are or you may always <a href="https://market.nativescript.org/">be part</a> of the community and write your own components/widgets/plugins. By speaking of writing your own means writing in native language(s).</p><p>So why I said a weekend project at the beginning?</p><p>NativeScript got my interest again with their Vue.js integration (Idk if it’s the way of writing what they’ve done) so I wanted to give a try again.</p><p>Their Playground is great and reminded me my days of <a href="https://expo.io/">Expo</a> and React before switching to Vue.js (I think Vue.js is the backyard of React developers where they smoke after long hours of frustration)</p><p>But (there’s always one), I think it still has time to grow. I can’t tell why in a very specific way but it seems to me too early start a commercial project with <a href="https://docs.nativescript.org/vuejs/nativescript-vuejs">NativeScript+Vue.js</a></p><p>About the Flutter.</p><p>They are doing their part as NativeScript does. Build native apps not with JavaScript but its lookalike <a href="https://www.dartlang.org/">Dart</a> language. They even have <a href="https://flutter.io/docs/get-started/flutter-for/react-native-devs">a specific page</a> how easy to switch between them.</p><p>The speed part is a go for the Flutter but the Dart? Nope. I could only do learn that language if I’ve never learnt the JavaScript. For the components? Good luck with <a href="https://docs.flutter.io/">the Docs</a> which is basically written for the dev team, by them.</p><p>At the and of the weekend project I’m still with my beloved plain and simple Vue.js with a little slowness on mobile apps. I’m OK.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eeb0354eb2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing multilingual applications]]></title>
            <link>https://itnext.io/managing-multilingual-applications-c97628d54011?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/c97628d54011</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[multilingualism]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 17:33:10 GMT</pubDate>
            <atom:updated>2020-03-03T07:05:03.176Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Head note:</em></strong><em> Sorry folks, project discontinued and cannot be maintained because of financial problems. Article here will stay for inspiration for other fellow developers.</em></p><p>Today I’d like to introduce you our new service called <a href="http://t9n.ist/">T9N Manager</a>.</p><p>BLUF: It is free for personal and open-source projects. Also has paid version for commercial use with extended functions, in very soon future.</p><p>Building a large scale application is hard for teams, harder for single developers with low budget and much more harder for anyone if the application is multilingual.</p><p>We’ve experienced that first hand during our ongoing project, then T9N Manager was born. As it became a standalone module within our application, we wanted to separate and share into the world of developers.</p><p>We are working mostly on Vue.js at the front and PHP at the back-end. So the translation files we produce are should be usable with <a href="https://github.com/kazupon/vue-i18n">vue-i18n</a>. It basically requires file formats like this:</p><pre>// translations-all.js</pre><pre>export const messages = {<br>  en: {<br>    message: {<br>      hello: &quot;hello world!&quot;<br>    }<br>  },<br>  tr: {<br>    message: {<br>      hello: &quot;merhaba dünya!&quot;<br>    }<br>  }<br>}</pre><p>With a proper configuration, you can separate translations into distinct files:</p><pre><em>// en-US.js</em></pre><pre>export const messages = {<br>  message: {<br>    hello: &quot;hello world!&quot;<br>  }<br>}</pre><pre><em>// tr-TR.js</em></pre><pre>export const messages = {<br>  message: {<br>    hello: &quot;merhaba dünya!&quot;<br>  }<br>}</pre><p>And get rid of named exports:</p><pre><em>// en-US.js</em></pre><pre>export default {<br>  hello: &quot;hello world!&quot;<br>}</pre><pre><em>// tr-TR.js</em></pre><pre>export default {<br>  hello: &quot;merhaba dünya!&quot;<br>}</pre><p>As the amount of your keys (eg. <em>hello </em>in above examples) increases, it’ll become harder and harder to keep those files synchronized. Most of the time vue-i18n or some other plugin of your framework will tell you when a particular key missing on a file, but it’ll not ease the pain of walking two steps forward and one back each time you forget to add a key to your second or third (even fourth?) class translations file.</p><p>I don’t even want to mention what happens when you decide a key is not very definitive for the context it has and needs to be changed. You know what I mean right? I bet yes, you do developer. Now you go back all of your translations files and find that ugly key and replace with new one.</p><p>Then T9N Manager comes to help you.</p><p>When you register and login to T9N, the Projects screen welcomes you with emptiness:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gECZ8wmvlNzfiiRkKPQKxw.png" /><figcaption>You know what it wants.</figcaption></figure><p>T9N works with Translation Projects. You should create a project first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkAf3IdvNEH4Y4RW_OLBuw.png" /><figcaption>A fancy modal of inputs</figcaption></figure><p>We have 700+ locales listed in our database, thanks to <a href="https://gist.github.com/jacobbubu/1836273">jacobbubu</a>. You can search and add how much you want to include into your project. There are also -<em>only informative purpose for the moment</em>-<em> Status</em> and <em>Default language</em> options. Default language option <strong>will</strong> allow users to produce files like this;</p><pre><em>// tr-TR.js</em></pre><pre>export default {<br>  &quot;hello world!&quot;: &quot;merhaba dünya!&quot;<br>}</pre><p>So, if you define your keys with the translations of native language of your app, which is English (US) for the above example, you will not need to produce a en-US.js file each time.</p><p>After you create the first project, it’ll be shown on the list like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-55iMYhw5rFMPqDe1pVMIQ.png" /></figure><p>The pale-blue line (a progress bar actually) below the project name shows the progress of your keys/translations state in percentage. So you’ll know how far you gone.</p><p>When you enter the project by clicking the open book icon at the beginning of the list, you’ll see this screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xy0Gumaa8Wa0zJNHakhtCQ.png" /></figure><p>You can start a project from nothing just by clicking Create a Key button or import your existing translation files by dragging and droping into the screen. File imports currently supports js and json files and we have a plan to include XML files very soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*pe4JVXNLcqdfBP9V96WfmQ.png" /><figcaption>Once you created a new key, you’ll see that on the sidebar.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpAY6FItse-aS5o_7HcODg.png" /><figcaption>Our first key!</figcaption></figure><p>You can select and unselect the keys listed on sidebar. When you select a key you’ll see the screen above. <em>Rename this key</em> field shows prefix of root just for information. When you need to use this key in your files, for example Vue.js with vue-i18n plugin, it should be used like this: $(‘hello’)</p><p>Now we came to the fancy parts.</p><p>We wanted T9N to be faster than editing js files on your IDE. To accomplish this idea, we’ve developed a way to create new keys under parent keys with dot notation.</p><p>Normally, to create new keys under another key, you have to select the key and click Create a Key button again. It’s not so hard for a single child key, but it becomes an exhausting work when you need to create a key tree like this:</p><pre>export default {<br>  &quot;modules&quot;: {<br>    &quot;layout&quot;: {<br>      &quot;sidebar&quot;: {<br>        &quot;alerts&quot;: {<br>          &quot;some-alert&quot;: &quot;hey yo!&quot;,<br>          &quot;some-negative-alert&quot;: &quot;nope dude!&quot;<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>To end up a nested object like this above, to create the <strong><em>some-alert</em></strong> key, one should click the Create a Key button for five times and press enter.</p><p>To overcome this issue, we’ve implemented dot notation to key renaming function. You just need to use dots between new keys when you updating a soon-to-be parent key:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWJR1VjwCXVWz9CkojtdZA.png" /></figure><p>When you hit the Update Key button, you’ll see your sidebar with a new look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*8TjIGCokxcIlWNWrX4tFjA.png" /><figcaption>Pretty fast, isn’t it?</figcaption></figure><p>Creating keys are fast. But what about relocating them? We also developed a faster version of cuting from there and pasting over here. There’s a secret menu next to Keys List title. Lets click the Relocate Selected Key item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*PIk_YQ1B3SJDXcUvDymFqA.png" /></figure><p>When you click it, sidebar turns into Key Relocation Mode;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*g9Ep1IeDc6mSr_WDc0eZgg.png" /></figure><p>You can select a new parent key, press Esc to cancel or click cancel icon. Once you select a new parent, it needs you to update the key with new parents structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0wCmhs3WX-NC-DRPBxG6Q.png" /><figcaption>Just hit the Update Key button.</figcaption></figure><p>You can update the key here with new parent, or cancel the relocation by hitting Revert to Original button.</p><p>Without using the relocation link inside the menu, you can always use Edit Parent Keys button to relocate a key to another parent.</p><p>When you on this screen above, you can create new parent keys too. Just type your new key names in <em>Relocate this node</em> field and hit Enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*SXLIlTXVCAt6yW2qQE0Mvw.png" /></figure><p>When you update the key, you’ll see your new structure on sidebar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*vj72Dp2ApaZj6otz2YsCyQ.png" /></figure><p>Now you know how to create and relocate keys. It’s time to export our files. Go to the secret menu and find/click Export Project link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQE9ZxDpco6dIty38FfNCg.png" /></figure><p>In this screen, you should select the locale from left, rename your file name if you want to, add some headers if you need to exclude this file from your linters. You also have option for exporting a pure json file or js file with default or custom export expression. If you port the browser’s downloads target to your languages folder, you will not be doing copy/pasting downloaded files from your downloads folder to your project.</p><p>There are a lot to tell about T9N, but most of it is the content of its documentation.</p><p><a href="http://vue-js.org/">Vue.js</a> and <a href="http://quasar-framework.org/">Quasar Framework</a> made it possible to create and I personally like to mention those people working hard for the open source universe.</p><p>Please share this post if you’d like to use T9N for your current or next project and show us your support.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c97628d54011" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/managing-multilingual-applications-c97628d54011">Managing multilingual applications</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to mutate Arrays of Objects with vue-apollo]]></title>
            <link>https://itnext.io/how-to-mutate-arrays-of-objects-with-vue-apollo-26a3ed80ba76?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/26a3ed80ba76</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[laravel-5]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Sun, 20 May 2018 09:32:02 GMT</pubDate>
            <atom:updated>2018-05-21T11:49:32.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u476kHK476FEud2dLd9sbg.png" /><figcaption>You can create interfaces like this with <a href="http://quasar-framework.org/">Quasar Framework</a> btw.</figcaption></figure><p>There are times that a title can’t explain enough the context of an article. A better one for this article is something should like “How to learn mutations of Array of Objects with vue-apollo in Laravel GraphQL” but it’s way too complex to explain a bit of code.</p><p>I try to write articles about the problems that occur while developing this project of mine and their solutions. For this time, it’s the mutation of Arrays.</p><p>I’m using Laravel in my projects since it’s version was 4ish. So it’s hard to break our bond after this long. Vue.js lets me seperate the Views from Laravel yet it’s still powerfull for APIs. Also it’s hard for a developer like me to learn another backend tech while still in the process of learning a client side tech.</p><p>But for my point of view, learning the GraphQL is not that hard as learning a new programming language. There are good sources like <a href="https://webonyx.github.io/graphql-php">Webonyx</a> PHP implementation of GraphQL and <a href="https://github.com/Folkloreatelier/laravel-graphql">Folklore’s</a> of Laravel. I assume that you’re already familiar of those since you read this far with patience.</p><p>I prefer to use <a href="https://github.com/rebing/graphql-laravel">rebing/graphql-laravel</a> just because it has some little extra over Folklore’s code. I’d like to skip the parts of installation, configuration etc. and go to code directly;</p><p>This is the example of a <em>schema</em> key in the <strong>config/graphql.php</strong> which has a query and mutation definitions;</p><pre><strong>&#39;system/translationManager&#39;</strong> =&gt; [<br>    <strong>&#39;query&#39;</strong> =&gt; [<br>        <strong>&#39;projects&#39;</strong> =&gt; \App\GraphQL\Queries\System\TranslationManager\ProjectsQuery::class,<br>    ],<br>    <strong>&#39;mutation&#39;</strong> =&gt; [<br>        <strong>&#39;updateProject&#39;</strong> =&gt; \App\GraphQL\Mutations\System\TranslationManager\Projects\UpdateProjectMutation::class<strong><br>    </strong>],<br>    <strong>&#39;middleware&#39;</strong> =&gt; [&#39;throttle&#39;]<br>],</pre><p>As you see from the example, my Laravel API has multiple GraphQL endpoints. To <em>query</em> or <em>mutate</em> <strong>projects</strong> in this API, <em>/system/translationManager</em> suffix should be added to <em>/graphql</em> url when using the apollo methods.</p><p>Projects Query is simply serves the translation projects data and includes <strong>id</strong>, <strong>name</strong>, <strong>status</strong> and <strong>list of locales</strong> that collected from a pivot table.</p><p>In the Edit Project Vue component, there’s a <strong>list of locales</strong> that included in the project and user may add/remove <strong>locales</strong>. Here is a example of a project data with the list <strong>locales</strong>;</p><pre><strong>data</strong> () {<br>  <strong>return</strong> {<br>    <strong>id:</strong> 6,<br>    <strong>name:</strong> &#39;My First Translation Project&#39;,<br><strong>    status:</strong> &#39;active&#39;,<br><strong>    locales:</strong> [<br>      {<br>       <strong>id:</strong> 2,<br>       <strong>identifier:</strong> &#39;tr-TR&#39;,<br>       <strong>description:</strong> &#39;Turkish (Turkey)&#39;<br>      }, {<br><strong>       id:</strong> 3,<br><strong>       identifier:</strong> &#39;en-GB&#39;,<br><strong>       description:</strong> &#39;English (United Kingdom)&#39;<br>      }<br>    ]<br>  }<br>}</pre><p>Assume the user has modified the data and it’s time to update the model. The first thing is to create a InputObject Type in Laravel. But to give a better explanation, I’ll give the Query and Type definitions first.</p><p>You may think that I already have my Type of locales that already been used when locales data served to client. Then why should we need another Type? But in reality, that Type of locales can only serve the data. Imagine it is a computed data of Vue.js components with custom getter/setter functions. Query Types in Laravel GraphQL are the getters and InputObject Types are the setters for Array data.</p><p>Here is the Locales Type (getter);</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/098c05f407696606e922e6fb4b8cda84/href">https://medium.com/media/098c05f407696606e922e6fb4b8cda84/href</a></iframe><p>This is the Projects Type;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71847717beff237e7083e0f9c2cb1e39/href">https://medium.com/media/71847717beff237e7083e0f9c2cb1e39/href</a></iframe><p>We use both types in Projects Query, just after defining them in <em>config/graphql.php</em>;</p><pre>&#39;types&#39; =&gt; [<br>    <strong>&#39;locales_type&#39;</strong> =&gt; \App\GraphQL\Types\System\Localization\LocalesType::class,<br><br>    <strong>&#39;projects_type&#39;</strong> =&gt; \App\GraphQL\Types\System\TranslationManager\ProjectsType::class<br>],</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe2b78084e653483a256d030c3aca1ae/href">https://medium.com/media/fe2b78084e653483a256d030c3aca1ae/href</a></iframe><p>Now we are ready to define InputObject Type of Locales (setter);</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02f86f2e4d98f66b91296fafb7679269/href">https://medium.com/media/02f86f2e4d98f66b91296fafb7679269/href</a></iframe><p>And we should add this to <em>config/graphql.php</em> too;</p><pre>&#39;types&#39; =&gt; [<br>    &#39;locales_type&#39; =&gt; \App\GraphQL\Types\System\Localization\LocalesType::class,</pre><pre><strong>    &#39;locales_input_object_type&#39; =&gt; \App\GraphQL\Types\InputObjects\LocaleInputObjectType::class,</strong></pre><pre>    &#39;projects_type&#39; =&gt; \App\GraphQL\Types\System\TranslationManager\ProjectsType::class<br>],</pre><p>We now use everything in the UpdateProject Mutation;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2485be92ea8c63c1161426dbd45e933/href">https://medium.com/media/a2485be92ea8c63c1161426dbd45e933/href</a></iframe><p>The final step is to send mutation from our application;</p><pre><strong>this</strong>.$apollo.mutate({<br>  mutation: gql`mutation ($id:Int!, $name:String!, $status:String!, $locales:<strong>[LocaleInputObjectType]</strong>) {<br>    updateProject (id:$id, name:$name, status:$status, locales:$locales) {<br>      id<br>      name,<br>      status<br>    }<br>  }`,<br>  variables: {<br>    id: id,<br>    name: name,<br>    status: status,<br>    <strong>locales: locales</strong><br>  },<br>  context: {<br>    <strong>uri: process.env.API_URL + &#39;/graphql/system/translationManager&#39;</strong><br>  }<br>}).then((data) =&gt; {<br>  console.log(data)<br>}).catch((error) =&gt; {<br>  console.error(error)<br>})</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26a3ed80ba76" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-mutate-arrays-of-objects-with-vue-apollo-26a3ed80ba76">How to mutate Arrays of Objects with vue-apollo</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic component creation in Vue.js]]></title>
            <link>https://itnext.io/dynamic-component-creation-in-vue-js-b002bb41aaf4?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/b002bb41aaf4</guid>
            <category><![CDATA[vue-series]]></category>
            <category><![CDATA[quasarframework]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[progressive-web-app]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Wed, 16 May 2018 09:26:24 GMT</pubDate>
            <atom:updated>2020-02-24T17:39:08.156Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is the deal;</p><p>You are creating a form with a recurring list of fields, for example;</p><ol><li>a list of phone numbers, addresses, tags, names etc.,</li><li>a wish list, inputs has search functions embedded with them,</li><li>a todo app maybe? really? still in 21st century?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kf37tRiP21JCskyNvoV6ww.png" /><figcaption>Maybe something like this?</figcaption></figure><p>If you are a JavaScript developer, you’d do;</p><ol><li>Create the template of a single line of the form inputs,</li><li>Put some “add/remove” buttons or icons at the end of the line,</li><li>Use jQuery clone command and append/prepend at the end or beggining of the list of lines,</li><li>Reset the fresh line of input’s contents and focus them so user can catch what was just happened.</li></ol><p>But, if you are developing with Vue.js, you should know something more than that. Because you have now components, watchers and some other mind-blowing stuff to use, and once you did, you may use again somewhere else. So copy/pasting the snippets, is not just copy/pasting snippets anymore. It’s the time to stop your employer to mock yourself about being copy/pasting employee of the month (or of the year?)</p><p>The first thing is to create a reusable component. I’ll make a phone numbers component which I’ll later use inside of my Create Contact page of my application. But the point is to use the same phone numbers component also inside of Edit Contact page and maybe Show Phone Number page so on.</p><p>Since I’m using <a href="https://quasar.dev/introduction-to-quasar">Quasar Framework</a>, <em>which is fantastic by the way</em>, I’ll use some other components of it. So don’t mind the tags starts with lowercase Q plus dash, they’ll do the work what they meant after the dash (Q-Field is a form field, Q-Input is a form input etc.) They also have some special attributes of Quasar but all are self-explaining. And you may replace them with native div/input tags in seconds.</p><p>Here is the template of our fellow PhoneNumberLine component;</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;div <strong>v-for=&quot;(line, index) in lines&quot;</strong> <strong>:key=&quot;index&quot; </strong>class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-6&quot;&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>          &lt;div class=&quot;col-2&quot;&gt;<br>            &lt;q-select<br>              <strong>v-model=&quot;line.countryCode&quot;</strong><br>              label=&quot;Country Code&quot;<br>              :options=&quot;countryPhoneCodes&quot;<br>            /&gt;<br>          &lt;/div&gt;<br>          &lt;div class=&quot;col-10&quot;&gt;<br>            &lt;q-input<br>              <strong>v-model=&quot;line.number&quot;</strong><br>              label=&quot;Phone Number&quot;<br>              type=&quot;tel&quot;<br>              placeholder=&quot;5551234567&quot;<br>              value=&quot;&quot;<br>            /&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;col-lg-4&quot;&gt;<br>        &lt;q-select<br>          <strong>v-model=&quot;line.phoneUsageType&quot;</strong><br>          label=&quot;Type of Usage&quot;<br>          :options=&quot;phoneUsageTypes&quot;<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;col-lg-2&quot;&gt;<br>        &lt;div class=&quot;block float-right&quot;&gt;<br>          &lt;q-btn round <strong>@click=&quot;removeLine(index)&quot;</strong> icon=&quot;delete&quot; /&gt;<br>          &lt;q-btn round v-if=&quot;index + 1 === lines.length&quot; <strong>@click=&quot;addLine&quot;</strong> icon=&quot;playlist-plus&quot;/&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*XRMAljxc8U3JoXaEjGAMqw.png" /><figcaption>Basic view of the component</figcaption></figure><p>I’ve highlighted the important parts of the code. To give better explanation of those from top to bottom;</p><ol><li>We have an <em>array</em> (named as <strong>lines</strong>) in the data section of the component and it’s used in <a href="https://vuejs.org/v2/guide/list.html#Mapping-an-Array-to-Elements-with-v-for">v-for directive</a>,</li><li>There should be <a href="https://vuejs.org/v2/guide/list.html#key">key binding</a> so Vue.js can track the elements of the list to be created and that is our <strong>index</strong>,</li><li>Inputs will use <a href="https://vuejs.org/v2/guide/forms.html">v-model directive</a> to bind their values into their <strong>line</strong> <em>object</em> within <strong>lines</strong> <em>array</em>. That means <strong>line</strong> <em>object</em> should contain <strong>countryCode</strong>, <strong>number</strong>, and <strong>phoneUsageType</strong> <em>keys</em> in itself.</li><li>And finally there are our buttons to remove and add new lines. Delete button has <strong>removeLine</strong> <em>method</em> with <strong>index</strong> as attribute and the other button has simply <strong>addLine</strong> <em>method</em> has binded to their <a href="https://vuejs.org/v2/guide/events.html#Listening-to-Events"><strong>click</strong></a> <em>event.</em></li></ol><p>Now we are ready to create the rest of our component;</p><pre>&lt;script&gt;<br><strong>export default </strong>{<br>  name: &#39;PhoneNumberLine&#39;,<br>  data () {<br>    <strong>return </strong>{<br>      lines: [],<br>      blockRemoval: <strong>true,</strong><br>      phoneUsageTypes: [<br>        {<br>          label: &#39;Home&#39;, value: &#39;home&#39;<br>        }, {<br>          label: &#39;Work&#39;, value: &#39;work&#39;<br>        }, {<br>          label: &#39;Mobile&#39;, value: &#39;mobile&#39;<br>        }, {<br>          label: &#39;Fax&#39;, value: &#39;fax&#39;<br>        }<br>      ],<br>      countryPhoneCodes: [<br>        {<br>          label: &#39;+90&#39;,<br>          value: &#39;+90&#39;<br>        }, {<br>          label: &#39;+1&#39;,<br>          value: &#39;+1&#39;<br>        }<br>      ]<strong><br>    </strong>}<br>  },<br>  watch: {<br>    lines () {<br>      <strong>this</strong>.blockRemoval = <strong>this</strong>.lines.length &lt;= 1<br>    }<br>  },<br>  methods: {<br>    addLine () {<br>      <strong>let </strong>checkEmptyLines = <strong>this</strong>.lines.filter(line =&gt; line.number === <strong>null</strong>)<br><br>      <strong>if </strong>(checkEmptyLines.length &gt;= 1 &amp;&amp; <strong>this</strong>.lines.length &gt; 0) {<br>         <strong>return<br></strong>      } <strong><br><br>      this</strong>.lines.push({<br>        countryCode: <strong>null</strong>,<br>        number: <strong>null</strong>,<br>        phoneUsageType: <strong>null<br>      </strong>})<br>    },<br><br>    removeLine (lineId) {<br>      <strong>if </strong>(!<strong>this</strong>.blockRemoval) {<br>         <strong>this</strong>.lines.splice(lineId, 1)<br>      }<br>    }<br>  },<br>  mounted () {<br>    <strong>this</strong>.addLine()<br>  }<br>}<br>&lt;/script&gt;</pre><p>Above, <strong>lines</strong> <em>array</em> you already know about a bit. But the other code does;</p><ol><li><strong>blockRemoval</strong> <em>key</em> of data <em>object</em> is simply blocks the removal of our last line of inputs when it’s set to <strong>true </strong>inside the <strong>lines</strong> <em>array</em> <strong>watch </strong><em>method</em>.</li><li><strong>phoneUsageTypes</strong> and <strong>countryPhoneCodes</strong> keys are just data providers to select inputs.</li><li>In <strong>lines</strong> <em>watcher</em>, Vue tracks the <strong>lines</strong> <em>array</em>’s length and toggles <strong>blockRemoval</strong>.</li><li><strong>addLine</strong> <em>method</em>, when triggered by the related button, first checks how many phone number fields are empty then checks how many lines we have in total and it blocks new line creation if there’s empty phone number fields already and more than zero lines. That does so because when the component is rendered, <strong>lines</strong> <em>array</em> is empty and there shouldn’t be any line is rendered in v-for directive. But since this method checks the empty fields and total lines length together, it’ll allow to create the first empty line when the component is mounted.</li><li><strong>addLine</strong> <em>method</em> finally pushes an empty object to <strong>lines</strong> <em>array</em> and thanks to our reactive v-for directive, there should our new line of inputs to be created automatically.</li><li><strong>removeLine</strong> <em>method</em> checks the <strong>blockRemoval</strong> <em>key</em> and removes the related item from <strong>lines</strong> <em>array</em>. v-for directive does the rest and removes line of inputs from our form.</li><li>And there is our <strong>mounted</strong> <em>function</em> calls the <strong>addLine</strong> <em>method</em> once and creates our very first empty line.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QTyIP-JHXzzshDWmpGgyXw.gif" /><figcaption>Adding New Line</figcaption></figure><p>Here you have it. The final version does;</p><ol><li>Prevents last line to be removed,</li><li>Prevents to add new line if there’s already an empty one,</li><li>Keeps persistent records of the input data.</li></ol><p>This is the finished code of this tutorial:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b022c6c82153ea5e734adeefde6454b/href">https://medium.com/media/6b022c6c82153ea5e734adeefde6454b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b002bb41aaf4" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/dynamic-component-creation-in-vue-js-b002bb41aaf4">Dynamic component creation in Vue.js</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Quasar Ajax Bar within every component]]></title>
            <link>https://onur-kose.medium.com/using-quasar-ajax-bar-within-every-component-b24165209313?source=rss-2553eefe2f32------2</link>
            <guid isPermaLink="false">https://medium.com/p/b24165209313</guid>
            <category><![CDATA[quasarframework]]></category>
            <category><![CDATA[single-page-applications]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Onur Köse]]></dc:creator>
            <pubDate>Thu, 10 May 2018 18:25:59 GMT</pubDate>
            <atom:updated>2018-05-11T14:51:12.013Z</atom:updated>
            <content:encoded><![CDATA[<p>In case you’ve missed, there is <a href="http://quasar-framework.org/">Quasar Framework</a>. The team behind has done an amazing job.</p><p>I’m trying to learn it just after the Vue.js and Quasar made me more ambitious about how the client-side will evolve in this era.</p><p>Loading components and displaying what’s going on to user is a bit burden in any SPA and Vue.js is not an exemption. But Quasar has a lot of components to overcome this flow. You have <a href="http://quasar-framework.org/components/ajax-bar.html">Ajax Bar</a>, <a href="http://quasar-framework.org/components/loading.html">Loading</a>, <a href="http://quasar-framework.org/components/inner-loading.html">Inner Loading</a>, <a href="http://quasar-framework.org/components/progress-bar.html">Progress Bar</a> and <a href="http://quasar-framework.org/components/spinner.html">Spinner</a> under the hood.</p><p>It was little bit tricky for me to find out how to use Ajax Bar component. It was simple at first, but gets complicated if you want second or third level routes.</p><p>The basic installation is the same as the other Quasar components. Add QAjaxBar to your quasar.conf.js file and &lt;q-ajax-bar /&gt; to your App.vue, below or above of the &lt;router-view /&gt;, it really doesn’t matter.</p><p>But what matters is starts just after this point. You can simply leave it like this and the fancy red line works with any Ajax request automatically. But what if you have a component that has it’s own children components? And who doesn’t has?</p><p>The good thing of Ajax Bar is, you can manually trigger it with start and stop functions. Since the component registered at the very root level, triggering from children requires a bit of labor.</p><p>Imagine you have your App.vue like this;</p><pre>&lt;template&gt;<br>  &lt;div id=&quot;q-app&quot;&gt;<br>    &lt;q-ajax-bar /&gt;<br>    &lt;router-view /&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>First thing to do is clearing that default 1000ms delay from the Ajax Bar props (<em>it requires Int, so “0” will not work if you put directly to delay attribute</em>);</p><pre>&lt;template&gt;<br>  &lt;div id=&quot;q-app&quot;&gt;<br>    &lt;q-ajax-bar <strong>:delay=&quot;delay&quot;</strong> /&gt;<br>    &lt;router-view /&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>export default {<br>  name: &#39;App&#39;,<br>  data: () =&gt; {<br>    return {<br>      <strong>delay: 0</strong><br>    }<br>  },<br>  methods: {},<br>  mounted () {}<br>}<br>&lt;/script&gt;</pre><p>There should be event listeners over the router-view, so we can call start/stop functions from children components;</p><pre>&lt;template&gt;<br>  &lt;div id=&quot;q-app&quot;&gt;<br>    &lt;q-ajax-bar <strong>ref=&quot;bar&quot; size=&quot;2px&quot; </strong>:delay=&quot;delay&quot; /&gt;<br>    <strong>&lt;router-view v-on:startAjaxBar=&quot;onStartAjaxBar&quot; v-on:stopAjaxBar=&quot;onStopAjaxBar&quot; /&gt;</strong><br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>export default {<br>  name: &#39;App&#39;,<br>  data: () =&gt; {<br>    return {<br>      delay: 0<br>    }<br>  },<br>  <strong>methods: {<br>    onStartAjaxBar () {<br>      console.log(&#39;started&#39;)<br>      this.$refs.bar.start()<br>    },<br>    onStopAjaxBar () {<br>      console.log(&#39;stopped&#39;)<br>      this.$refs.bar.stop()<br>    }<br>  },</strong><br>  mounted () {}<br>}<br>&lt;/script&gt;</pre><p>Note that we now also have the ref attribute on &lt;q-ajax-bar /&gt;(<em>Checkout </em><a href="https://vuejs.org/v2/api/#vm-refs"><em>Vue.js docs</em></a><em> for further reading</em>). It basically attaches vDOM elements to Vue instance, which is collected into this.$refs object so we can use it inside our methods. The bad part of the refs object, it’s bound the component that creates the element. So you can’t get refs object from children routes. That’s why we listen our events from the router-view element. The good part is, you know, all that jQuery history of yours doesn’t remind you the good old days?</p><p>Well, now it’s time to trigger our events from a child route. Imagine our router file has some auth pages config like this, routes.js;</p><pre><strong>export default </strong>[<br>  {<br>    path: &#39;/&#39;,<br>    component: () =&gt; <strong>import</strong>(&#39;layouts/default&#39;),<br>    children: [<br>      { path: &#39;&#39;, component: () =&gt; <strong>import</strong>(&#39;pages/index&#39;) }<br>    ]<br>  },<br><br>  {<br>    path: &#39;/auth&#39;,<br>    component: () =&gt; <strong>import</strong>(&#39;layouts/auth&#39;),<br>    children: [<br>      { path: &#39;login&#39;, component: () =&gt; <strong>import</strong>(&#39;pages/auth/login&#39;) },<br>      { path: &#39;register&#39;, component: () =&gt; <strong>import</strong>(&#39;pages/auth/register&#39;) },<br>      { path: &#39;lost-password&#39;, component: () =&gt; <strong>import</strong>(&#39;pages/auth/lost-password&#39;) }<br>    ]<br>  },<br><br>  {<br>    path: &#39;*&#39;,<br>    component: () =&gt; <strong>import</strong>(&#39;pages/404&#39;)<br>  }<br>]</pre><p>We have a default layout for all the content, and auth layout for the auth pages only. That means auth layout has it’s own children. This is the auth.vue;</p><pre>&lt;template&gt;<br>  &lt;q-layout&gt;<br>    &lt;q-tabs color=&quot;primary&quot; align=&quot;justify&quot;&gt;<br>      &lt;q-route-tab name=&quot;login-content&quot; default slot=&quot;title&quot; icon=&quot;mdi-login-variant&quot; label=&quot;Login&quot; to=&quot;/auth/login&quot; exact /&gt;<br>      &lt;q-route-tab name=&quot;register-content&quot; slot=&quot;title&quot; icon=&quot;mdi-account-plus&quot; label=&quot;Register&quot; to=&quot;/auth/register&quot; exact /&gt;<br>      &lt;q-route-tab name=&quot;lost-password-content&quot; slot=&quot;title&quot; icon=&quot;mdi-textbox-password&quot; label=&quot;Lost Password&quot; to=&quot;/auth/lost-password&quot; exact /&gt;      <br>      <strong>&lt;router-view /&gt;</strong><br>    &lt;/q-tabs&gt;<br>  &lt;/q-layout&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>export default {<br>  name: &#39;Auth Layout&#39;,<br>  data () {<br>    return {}<br>  },<br>  methods: {},<br>  <strong>mounted () {<br>    let self = this<br>    this.$router.beforeEach((to, from, next) =&gt; {<br>      self.$emit(&#39;startAjaxBar&#39;)<br>      next()<br>    })<br>    this.$emit(&#39;stopAjaxBar&#39;)<br>  }</strong><br>}<br>&lt;/script&gt;</pre><p>Auth layout is a basic Tabs view with it’s own router-view element. You can see the mounted function has and immediate stopAjaxBar call so it stops whatever Ajax Bar occuring during initial document loading. Before that there’s our navigation guard that triggers App.vue’s events to start Ajax Bar. We now only need a stop trigger, login.vue;</p><pre>&lt;template&gt;<br>    &lt;q-tab-pane name=&quot;login-content&quot;&gt;<br>      &lt;h3&gt;Login Screen&lt;/h3&gt;<br><br>      &lt;div style=&quot;max-width: 90vw;&quot;&gt;<br>        &lt;p class=&quot;caption&quot;&gt;<br>          This is where the login form should placed<br>        &lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/q-tab-pane&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  name: &#39;Login Component&#39;,<br>  <strong>mounted () {<br>    this.$emit(&#39;stopAjaxBar&#39;)<br>  }</strong><br>}<br>&lt;/script&gt;</pre><p>Here you can see how the stop is triggered. But wait, this is a child component of auth layout, not App.vue. It means this $emit here, will not reach his grandfather. We should listen this from his father, auth.vue;</p><pre>&lt;template&gt;<br>  &lt;q-layout&gt;<br>    &lt;q-tabs color=&quot;primary&quot; align=&quot;justify&quot;&gt;<br>      &lt;q-route-tab name=&quot;login-content&quot; default slot=&quot;title&quot; icon=&quot;mdi-login-variant&quot; label=&quot;Login&quot; to=&quot;/auth/login&quot; exact /&gt;<br>      &lt;q-route-tab name=&quot;register-content&quot; slot=&quot;title&quot; icon=&quot;mdi-account-plus&quot; label=&quot;Register&quot; to=&quot;/auth/register&quot; exact /&gt;<br>      &lt;q-route-tab name=&quot;lost-password-content&quot; slot=&quot;title&quot; icon=&quot;mdi-textbox-password&quot; label=&quot;Lost Password&quot; to=&quot;/auth/lost-password&quot; exact /&gt;<br>      <strong>&lt;router-view v-on:startAjaxBar=&quot;onStartAjaxBar&quot; v-on:stopAjaxBar=&quot;onStopAjaxBar&quot; /&gt;</strong><br>    &lt;/q-tabs&gt;<br>  &lt;/q-layout&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  name: &#39;Auth Layout&#39;,<br>  data () {<br>    return<strong> </strong>{}<br>  },<br>  methods: {<br>    <strong>onStartAjaxBar () {<br>      console.log(&#39;started sent&#39;)<br>      this.$emit(&#39;startAjaxBar&#39;)<br>    },<br>    onStopAjaxBar () {<br>      console.log(&#39;stopped sent&#39;)<br>      this.$emit(&#39;stopAjaxBar&#39;)<br>    }</strong><br>  },<br>  mounted () {<br>    let self = this<br>    this.$router.beforeEach((to, from, next) =&gt; {<br>      self.$emit(&#39;startAjaxBar&#39;)<br>      next()<br>    })<br>    this.$emit(&#39;stopAjaxBar&#39;)<br>  }<br>}<br>&lt;/scrip&gt;</pre><p>So auth.vue transfers both start and stop events from his children to his parent component and listens those events from it’s own router-view element.</p><p>There might be better implementations out there in the wilderness, but it does work for the moment, and it’s all that matters for now.</p><p>Please shake some hands if you find these notes useful to yourself.</p><p>Edit: Here are the gist of those codes above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/564c4325e227c8e2d088b70f12da5db5/href">https://medium.com/media/564c4325e227c8e2d088b70f12da5db5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b24165209313" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>