<?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 Jia on Medium]]></title>
        <description><![CDATA[Stories by Jia on Medium]]></description>
        <link>https://medium.com/@jiahao831123?source=rss-fed3675a2c88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iNPV4pawSkjYkSmd09ubFw.jpeg</url>
            <title>Stories by Jia on Medium</title>
            <link>https://medium.com/@jiahao831123?source=rss-fed3675a2c88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:37:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jiahao831123/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[策略模式(Strategy Pattern)js範例]]></title>
            <link>https://jiahao831123.medium.com/%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F-strategy-pattern-js%E7%AF%84%E4%BE%8B-fc9e284ba6cf?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc9e284ba6cf</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[strategy-pattern]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:43:24 GMT</pubDate>
            <atom:updated>2023-01-28T06:15:56.790Z</atom:updated>
            <content:encoded><![CDATA[<h4>於js與vue中的實踐</h4><blockquote><em>策略模式是一種設計模式，它定義了一組算法，並將每一個算法封裝起來，使它們可以相互替換。這樣程序在運行時可以根據需要來選擇不同的算法。</em><strong><em>策略模式使得算法可以獨立於使用它的客戶而變化</em></strong><em>。 — chat GPT</em></blockquote><p>對我來說，策略模式我認為最重要的部分，就是<strong>算法</strong>可獨立於他的客戶(這邊的客戶代表調用此算法的某個模組或方法或類別)。獨立的好處代表一但算法有更新，算法有新增，算法有刪除，程式碼部分僅更新算法寫法就好，客戶都不需要進行修改。這樣的好處在於好擴充與好維護。</p><h4>js中的實踐</h4><p>js 中可替代部分ifelse 或 switch 寫法，皆以印射方式實現策略模式。</p><p>以下是一隻產生相對應訊息類別的function，參數為訊息類別，回傳對應訊息類別物件。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FLvlUlb6WAimY5x7NatOA%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FLvlUlb6WAimY5x7NatOA&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/65a9838b66bb05487bb83c660eba7ebb/href">https://medium.com/media/65a9838b66bb05487bb83c660eba7ebb/href</a></iframe><p>此時運用策略模式精神，將算法獨立於客戶端，此時的客戶端就是getMessage此函數。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FaMw5hzi4JgTyR6g28qkx%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FaMw5hzi4JgTyR6g28qkx&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd5208fc298e5536c053d8d013e50790/href">https://medium.com/media/cd5208fc298e5536c053d8d013e50790/href</a></iframe><p>此時就將策略與客戶(getMessage)隔離出來，此時策略的實作與客戶以不相干，客戶僅專注於調用，而實作交予策略決定，此方法的好處</p><ol><li>符合單一職責原則：客戶僅專注於調用策略，策略的新增刪除修改僅在策略實踐。</li><li>符合開放封閉原則：無須對客戶端進行修改就能新增策略。</li></ol><h4>Vue中的實踐</h4><p>vue中template動態組件常用is props做動態組建的切換以代替使用ifelse，因此每個組件有各自bind所要綁定的props與on事件，也可利物件包裝進行策略模式的實踐。以下是簡單範例</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Fhr3m4ofao7hCfr5gsTea%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Fhr3m4ofao7hCfr5gsTea&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ec072ccaca9ba54bcdfff0f80082281/href">https://medium.com/media/9ec072ccaca9ba54bcdfff0f80082281/href</a></iframe><p>此寫法的壞處在於，只要有新增訊息類別，模板要改，相對應的策略要要新增於script中，因此也可利用測略並搭被is v-bind on關鍵字搭配策略包裝起來。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Fh2zhMB30e46MC4rNbPSv%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Fh2zhMB30e46MC4rNbPSv&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b55413b670771bde56f5fbd6c53acd6e/href">https://medium.com/media/b55413b670771bde56f5fbd6c53acd6e/href</a></iframe><h3>Refrence</h3><p><a href="https://refactoringguru.cn/design-patterns/strategy">策略设计模式</a></p><h4>首頁</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc9e284ba6cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[js設計模式範例]]></title>
            <link>https://jiahao831123.medium.com/js%E8%A8%AD%E8%A8%88%E6%A8%A1%E5%BC%8F%E7%AF%84%E4%BE%8B-de00a748100b?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/de00a748100b</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 05:04:20 GMT</pubDate>
            <atom:updated>2023-01-28T05:44:46.222Z</atom:updated>
            <content:encoded><![CDATA[<p>設計模式定義就不再贅述，此篇記錄一下我在產品專案中有用到的設計模式，也做紀錄。</p><p><a href="https://jiahao831123.medium.com/%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F-strategy-pattern-js%E7%AF%84%E4%BE%8B-fc9e284ba6cf">策略模式(Strategy Pattern)</a><br>狀態模式(Status Pattern)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de00a748100b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue Vite <--- Last few GCs --->]]></title>
            <link>https://jiahao831123.medium.com/vue-vite-last-few-gcs-b0d6fabc0fd2?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0d6fabc0fd2</guid>
            <category><![CDATA[vites]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Fri, 19 Aug 2022 07:47:52 GMT</pubDate>
            <atom:updated>2022-08-19T07:47:52.109Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.08.19</p><h4>環境：</h4><p>vue+vite</p><p>最近公司從macbook air 16g 換成 mini 8g，在建置時會跳出Last few GCs 的錯誤 ，查了一下是記憶體溢出問題，加入 “NODE_OPTIONS= — max-old-space-size=8192” 在建置指令中可順利建置</p><h4>結論</h4><pre>//in package.json<br>&quot;script&quot;:{<br>....<br>&quot;build&quot;:&quot;vite build&quot;<br>-&gt;<br>&quot;build&quot;:&quot;NODE_OPTIONS=--max-old-space-size=8192  vite build&quot;</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0d6fabc0fd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unhandled Promise Rejection: RangeError: Invalid time value]]></title>
            <link>https://jiahao831123.medium.com/unhandled-promise-rejection-rangeerror-invalid-time-value-7ee7321fd740?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ee7321fd740</guid>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 04:32:12 GMT</pubDate>
            <atom:updated>2022-08-14T04:32:12.782Z</atom:updated>
            <content:encoded><![CDATA[<p>2022.8.14</p><h4><strong>先講結論：</strong></h4><p>safari 的環境的new Date()，吃的參數字串比chrome嚴格</p><pre>// chrome<br>new Date(&#39;2020-12-01 12:00:00&#39;)//pass<br>new Date(&#39;2020-12-12T12:00:00&#39;)//pass</pre><pre>//safari <br>new Date(&#39;2020-12-12 12:00:00&#39;)//error<br>new Date(&#39;2020-12-12T12:00:00&#39;)//pass</pre><p>找尋程式裡new Date()部分，並檢查格式，修正格式，就能解決問題。</p><h4>情境：</h4><p>今天遇到客戶說，產品頁面打開一遍白，心理OS 怎麼可能？</p><p>看了客戶截圖，還真的是一遍白， ﾟДﾟ） ﾟДﾟ） ﾟДﾟ）</p><p>但有注意到一件事，客戶是用safari，就知道又是他在作怪</p><p>走了個ie，還有個safari==。</p><h4>環境：vue3+pinia+typescritp</h4><h4>debugger:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SV2ortnss_2r3du56tHWvw.png" /></figure><p>開了safari 把開發者模式打開，只顯示了一行錯afari</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*J86Qo3mRr0QQ6eKDyD2C5g.png" /></figure><p>他只噴了這行</p><blockquote>Unhandled Promise Rejection: RangeError: Invalid time value</blockquote><p>程式哪行錯，哪隻檔案錯 完全不知道 這樣怎麼找啊(／‵Д′)／(／‵Д′)／</p><p>問了google 大神，大概鎖定問題是出在safari new Date 部分，一看畫面白的一想到就是渲染問題，所以就解決方式就是從vue 程式進入點 main.ts 開始，一路到App.vue 到最後渲染的組件一層一層的設中斷點…</p><p>最後發現出在某個組件，其組件有一段</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTJg2xPo5sCtRY8Mq7zfzw.png" /></figure><p>toDate 是一隻自己寫的function</p><pre>export const toDate = (date: string) =&gt; format(new Date(date), &#39;yyyy-MM-dd&#39;)</pre><p>大概是new Date 時出錯了，所以改造，拆分邏輯，並加入try catch，將空白替換成Ｔ</p><pre>export const getNewDate = (date: string): Date =&gt; {<br>  let _date = new Date()<br>  try {<br>    _date = new Date(date.replace(/ /g, &#39;T&#39;))<br>  } catch (error) {<br>    console.warn(&#39;@@newDateTimeError:&#39;, date)<br>  }<br>  return _date<br>}</pre><pre>export const toDate = (date: string) =&gt; format(getNewDate(date), &#39;yyyy-MM-dd&#39;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ee7321fd740" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS Class Singleton]]></title>
            <link>https://jiahao831123.medium.com/js-class-singleton-f808ede960b5?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/f808ede960b5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[singleton-pattern]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Fri, 26 Nov 2021 13:52:41 GMT</pubDate>
            <atom:updated>2021-11-26T13:52:41.425Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.11.26</p><p>關於JS 實作Singleton模式有許多教學文章，但大多都以function方式定義，而非Class方式定義，找了許多終於發現有一個影片是以Class 方式定義，是以Object.freeze 方式實踐，以下是參考影片寫出:</p><pre>class Singleton{<br>    constructor(){<br>        if(Singleton.instance instanceof Singleton){<br>          return Singleton.instance}<br>        this.SingletonObject={<br>            name:&#39;Singleton&#39;,<br>            version:1<br>        }<br>        Object.freeze(this)<br>        Singleton.instance = this<br>    }<br>    get(key){<br>        return this.SingletonObject[key]<br>    }<br>}<br>let a = new Singleton()<br>let b = new Singleton()<br>console.log(a===b)//output true</pre><h3>Refrence</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FC2NxMWQn85c%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DC2NxMWQn85c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FC2NxMWQn85c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/312b1fcd18c921ec259060f1b1ba005a/href">https://medium.com/media/312b1fcd18c921ec259060f1b1ba005a/href</a></iframe><p><a href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze">Object.freeze() - JavaScript | MDN</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f808ede960b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visual Studio 2022 安裝延伸模組問題]]></title>
            <link>https://jiahao831123.medium.com/visual-studio-2022-%E5%AE%89%E8%A3%9D%E5%BB%B6%E4%BC%B8%E6%A8%A1%E7%B5%84%E5%95%8F%E9%A1%8C-ef5997296380?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef5997296380</guid>
            <category><![CDATA[visualstudio-2022]]></category>
            <category><![CDATA[visual-studio]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 01:48:52 GMT</pubDate>
            <atom:updated>2021-11-12T01:48:52.692Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.11.12</p><p># 因為遺漏下列參考，所以無法安裝此延伸模組:Micorsoft.VisualStudio.Component.CoreEditor</p><h4>前言:</h4><p>最近 VisualStudio 2022 推出了，在同事的推坑下也去載來玩玩，聽到當下是覺得，會不會用2022 ，一些2019的擴充套件無法使用，沒想到一載，果然無法相容，我安裝的是 <a href="https://marketplace.visualstudio.com/items?itemName=MadsKristensen.HtmlForJavascript">HTML for Javascript </a>，我看她介紹是有支援2022的，但下載安裝檔安裝，就遇到問題了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*CEy-KrF8uRpILO2lAqv_NQ.png" /></figure><p>同事都說，這是相容問題，只能等一陣子，可能就會解決了，於是我問了我最強的同事，Google，有找到一篇是2017 到 2019 也是相容性問題的文章</p><p><a href="https://www.coder.work/article/6747864"><em>visual-studio — 安装 Visual Studio 扩展时缺少 Microsoft.VisualStudio.Component.CoreEditor</em></a></p><p>我直接去看解決方案，最後也成功在2022上安裝成功並使用，以下為解決步驟</p><ol><li><strong>下載安裝檔(vsix)</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/78/1*tKpI7m-1-1_XHa1Z98CoPw.png" /></figure><p><strong>2.解壓縮，沒錯，就是對他解壓縮，會得到一個資料夾</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/76/1*GjWbPptuCoVQr0iwR6vwfQ.png" /></figure><p><strong>3.修改資料夾內 catalog.json 與 extension.vsixmanifest 兩個文件</strong></p><p><strong>catalog.json</strong></p><p>由[15.0,16.0) 改為 [15.0,18.0)</p><blockquote>“Microsoft.VisualStudio.Component.CoreEditor”:”[15.0,18.0)”}</blockquote><p><strong>extension.vsixmanifest</strong></p><p>由[15.0,16.0) 改為 [15.0,18.0)</p><blockquote>&lt;Prerequisite Id=”Microsoft.VisualStudio.Component.CoreEditor” Version=”[15.0,18.0)” DisplayName=”Visual Studio core editor” /&gt;</blockquote><p><strong>4.將所有資料夾進行壓縮，並命名為.vsix 檔</strong></p><p>將資料夾所有檔案選取，右鍵-&gt;傳送到-&gt;壓縮的zipper資料夾，命名為vsix 檔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*1FcDu34W115bA95Df8U-JA.png" /></figure><p><strong>5.點擊vsix 安裝</strong></p><h3>Reference</h3><p><a href="https://www.coder.work/article/6747864">visual-studio - 安装 Visual Studio 扩展时缺少 Microsoft.VisualStudio.Component.CoreEditor</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef5997296380" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[有了Entity Framework是否還需要Repository Pattern?]]></title>
            <link>https://jiahao831123.medium.com/%E6%9C%89%E4%BA%86entity-framework%E6%98%AF%E5%90%A6%E9%82%84%E9%9C%80%E8%A6%81repository-pattern-29d862ef29b7?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/29d862ef29b7</guid>
            <category><![CDATA[repository-pattern]]></category>
            <category><![CDATA[ef-core]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 04:30:49 GMT</pubDate>
            <atom:updated>2021-11-07T04:30:49.126Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.11.07</p><p>這篇文章算是我的心理碎碎念，如果你不幸看到我的碎碎念，希望是你的前提是你懂Entity Framework 與 Repository Pattern XD</p><blockquote>前言:這一個問題之前工作上和組內夥伴有套論過，有了 Entity Framework 那是否還需要用 Repository Pattern?</blockquote><h3>一、網上反對方，反對EF+Repository</h3><p>其實也有相關文章說明有了EF 就不需要在寫Repository Pattern，如這篇:</p><p><a href="https://www.cnblogs.com/leotsai/p/entity-framework-doesnt-need-additional-repository.html"><strong>博客园的大牛们，被你们害惨了，Entity Framework从来都不需要去写Repository设计模式</strong></a></p><p>此篇作者反對使用EF 還用Repository Pattern 的前提想法是</p><blockquote><strong>EF本身就是repository设计模式的</strong></blockquote><p>所以既然EF 本身就是 Repository Pattern，你為何要在包一層 Repository 呢?</p><p><strong>並指出EF + Repository 的三大缺點</strong></p><ol><li>程式太醜(你需要多寫Repository去包)</li><li>難用(每個實體寫在不同 Repository，但有跨表的操作將會非常難操作)</li><li>有Bug(作者的論點不是很清楚，是指架構會讓人不小心寫出bug的程式)</li></ol><h3>二、網上同意方，認為Repository 還是有存在必要</h3><p>如這篇:</p><p><a href="https://dotblogs.com.tw/regionbbs/2017/07/18/simple_talk_about_repository_pattern">[.NET][Design Patterns] 無辜的 Repository Pattern</a></p><p>此篇作者認為，還是有其必要</p><pre>Repository 其實是存取資料的抽象化 API，只要是向資料儲存體放資料或要資料的功能，都會經由它來處理，有了抽象化的 API 後，上層的服務 (Service) 只要關心 Repository 的抽象化 API。</pre><p>作者認為，若是一個不需要抽會資料儲存體的應用程式，確實可以不實作Repository，但若有一天老闆發瘋要你換資料庫，那你就必須重寫了，作者最後的註解我也覺得寫得很棒很有道理</p><pre>當在業界久了，經歷了一些事情，或許你就會了解有時候隨手做的一些動作，有一天會為你省下不少時間，而沒做的話會讓你多了一堆工作。</pre><p>與這篇文章</p><p><a href="https://softwareengineering.stackexchange.com/questions/390061/dependency-inversion-vs-repository-pattern-app-layer-dependency-on-orm"><strong>Dependency inversion vs repository pattern (app layer dependency on ORM)</strong></a></p><pre><em>There is nothing about the repository pattern and dependency injection that is mutually exclusive.<br></em>存儲庫模式和依賴注入/服務模式沒有任何互斥的地方。</pre><pre>The primary purpose of the Repository Pattern (<a href="https://blog.kylegalbraith.com/2018/03/06/getting-familiar-with-the-awesome-repository-pattern/">example</a>) is to divorce your application logic from having to know anything about how to access the data<br>倉庫模式的主要目的是將應用程序邏輯與了解如何訪問數據分離開來。</pre><h3>三、我的想法</h3><p>最終，我的想法還是趨近於後者，就是<strong>Repository 還是有存在必要</strong>，</p><p>即使EF 也能夠輕易幫我們完成資料庫類型的抽換，但我認為Repository 最核心的幫助就是讓我們將業務核心與資料存取核心進行隔離，即使使用模式會讓程式碼變得更多，但也多了可讀性、可擴充與可維護性，我認為有以下好處</p><ol><li><strong>符合符合SOLID的 Dependency inversion principle</strong><br>高階模組不高依賴低階模組，兩者都該依賴於抽象；業務核心模組不該直接使用資料存取模組，應該利用Repository 當作介面隔離。</li><li><strong>統一存取介面，有利於擴充與維護 <br></strong>若不使用<strong>Repository，</strong>操作資料庫的方法將會散在業務層各處，若要統一在讀寫前加個方法，或記Log將會非常麻煩且不好維護</li><li><strong>替換資料庫僅更動Repository</strong>，就能進行</li></ol><p>若有理解錯誤可以通知我喔，今天先這樣</p><h3>Reference</h3><ul><li><a href="https://www.cnblogs.com/leotsai/p/entity-framework-doesnt-need-additional-repository.html">博客园的大牛们，被你们害惨了，Entity Framework从来都不需要去写Repository设计模式</a></li><li><a href="https://dotblogs.com.tw/regionbbs/2017/07/18/simple_talk_about_repository_pattern">小朱® 的技術隨手寫</a></li><li><a href="https://stackoverflow.com/questions/55130226/doesnt-repository-pattern-in-clean-architecture-violate-dependency-inversion-pr">Doesn&#39;t repository pattern in clean architecture violate Dependency inversion principle?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29d862ef29b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VueUse 10 分鐘]]></title>
            <link>https://jiahao831123.medium.com/vueuse-10-%E5%88%86%E9%90%98-4cf58d1486a7?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cf58d1486a7</guid>
            <category><![CDATA[vueuse]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Fri, 05 Nov 2021 01:24:33 GMT</pubDate>
            <atom:updated>2021-11-05T01:24:33.992Z</atom:updated>
            <content:encoded><![CDATA[<p>2021/11/05</p><h3>VueUse</h3><ul><li>1.什麼是VueUse</li><li>2.為甚麼要用VueUse</li><li>3.要怎麼用VueUse</li></ul><h3>一、什麼是VueUse?</h3><p><a href="https://vueuse.org/">VueUse官網</a></p><blockquote><em>VueUse 是一套 Vue ComposionApI 的常用</em><strong><em>工具集</em></strong><em>，他的初衷是將一切不支援JS 的API 變得支援響應。</em></blockquote><h3>二、為什麼要用VueUse</h3><h3>以實現地理資訊定位為例</h3><h4>不使用VuewUse</h4><p>Service.js</p><pre>Vuex store</pre><pre>    state: () =&gt; ({<br>        geolocationInfo: null,<br>    }),<br>    mutations: {<br>        setGeolocationInfo(state,payload) {<br>            state.geolocationInfo = payload<br>        }<br>    },<br>    actions: {<br>        updateGeolocationInfo(context){<br>            if (&quot;geolocation&quot; in navigator) {<br>                navigator.geolocation.getCurrentPosition( position =&gt; {<br>                    context.commit(&#39;setGeolocationInfo&#39;, position)<br>                    //console.log(`geolocation is update`)<br>                })<br>            } else {<br>                console.log (`geolocation IS NOT available`)<br>            }<br>        }<br>    },<br>    getters: {<br>        /**<br>         * 使用者定理資訊<br>         * @param {any} state<br>         * @returns{Object} GeolocationInfo<br>         */<br>        geolocationInfo(state) {<br>            return state.geolocationInfo<br>        },<br>        /**<br>         * 使用者座標<br>         * @param {any} state state<br>         * @returns{[Number,Number]} 座標陣列<br>         */<br>        userCoordinate(state) {<br>            if (!state.geolocationInfo) {<br>                console.log(`geolocationInfo is un init`)<br>                return undefined<br>            }<br>            console.log(state.geolocationInfo)<br>            const x = state.geolocationInfo.coords.longitude,<br>                  y = state.geolocationInfo.coords.latitude<br>            return [x,y]<br>        }<br>    }<br>}</pre><p>index.js</p><pre>...略</pre><pre>    created() {<br>        console.log(&#39;vue is loading&#39;)<br>        const me = this<br>        me.$store.dispatch(&#39;user/updateGeolocationInfo&#39;)</pre><pre>        //定時更新瀏覽者位置資訊<br>        const tenSecond = 10000,<br>              source = interval(tenSecond)<br>        this.geolocationInfoInterval = source.subscribe(() =&gt; {<br>           me.$store.dispatch(&#39;user/updateGeolocationInfo&#39;)<br>        })<br>        console.log(me.store.user.geolocationInfo)</pre><pre>    },</pre><p>為了要時時更新使用者地理位置資訊，必須定時抓取使用者資料，之後再進行監聽，而使用VueUse 的useGeolocation 他都將我們需要的功能包裝好。</p><p>使用VuewUse</p><pre>const { coords, locatedAt, error } = useGeolocation()</pre><pre>window.vue = new Vue({<br>    ...略<br>    created() {<br>        const me = this<br>        console.log(coords)<br>    },<br>    ...略<br>})</pre><p><a href="https://vueuse.org/core/usegeolocation/">useGeolocation</a></p><p>使用VueUse 只需要兩行程式碼就能使用，1.引入，2.使用。</p><h3>其他好用功能</h3><p><a href="https://vueuse.org/core/onClickOutside/">onClickOutside</a></p><h3>三.要怎麼用VueUse</h3><h4>Vue2 CDN</h4><p>1.安裝Vue2 composionAPI 擴充套件</p><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/@vue/composition-api@1.3.3&quot;&gt;&lt;/script&gt;</pre><p>2.安裝VueUse</p><pre>&lt;script src=&quot;https://unpkg.com/@vueuse/shared&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;https://unpkg.com/@vueuse/core&quot;&gt;&lt;/script&gt;</pre><p>3.要用時引入</p><pre>const { useGeolocation } = VueUse<br>const { coords, locatedAt, error} = useGeolocation()<br></pre><pre>...略<br>  created(){<br>    console.log(coords.value)<br>    <br>  },</pre><p><a href="https://codepen.io/misooncodepen/pen/OJjQMjq?editors=1010">線上測試 Code Pen CDN 環境</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cf58d1486a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Promise 五分鐘]]></title>
            <link>https://jiahao831123.medium.com/javascript-promise-%E4%BA%94%E5%88%86%E9%90%98-3b1a0ba711ec?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b1a0ba711ec</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Mon, 25 Oct 2021 02:04:19 GMT</pubDate>
            <atom:updated>2021-11-02T00:32:29.656Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.10.25</p><ol><li><strong>(What)Promise 是什麼?</strong></li><li><strong>(Why) Promise為什麼要用?</strong></li><li><strong>(How) Promise要怎麼用?</strong></li><li><strong>(Other) Promise與其他部分</strong></li></ol><h3>一、Promise是什麼?</h3><blockquote>Promise是一種JavaScript 語言中的物件，利用這個物件讓<strong>解決非同步問題</strong>的寫法更加<strong>簡潔直觀</strong>且好用。</blockquote><h3>二、為什麼要用Promise?</h3><blockquote>Promie是一種處理非同步問題的方法，非同步問題如前端向後端要取資料，資料並不是馬上回來，需要等待，以往<strong>利用callback方式解決</strong>，但寫法相較Promise利用.then()、.cathc()會較不直觀，利用Promise可以讓寫法更加簡潔直觀。</blockquote><h3>三、 Promise要怎麼用?</h3><p>一般向後端取資料日常</p><ol><li>向後端發起服務</li><li>把取回的資料，塞到本地。</li></ol><p><strong>callback寫法</strong></p><pre>//callback 寫法<br>let data</pre><pre>function getDataWithCallback(callback){ <br>   $.ajax({<br>   url:&#39;XXX&#39;,<br>   type:&#39;get&#39;,<br>   success:function(res){callback}<br>   error:function(){}})<br>}</pre><pre>getDataAndDealWithCallback(x=&gt;{data = x.data});</pre><p><strong>Promise改寫</strong><br>將程式碼利用Promise包裝起來並回傳，</p><p>定義reslove():成功後要回傳資料<br>定義reject():失敗後要回傳資料</p><pre>//Promise 寫法<br>let data</pre><pre>function getDataWithPromise(){ <br>   return new Promise((reslove,reject)=&gt;{<br>     $.ajax({<br>     url:&#39;XXX&#39;,<br>     type:&#39;get&#39;,<br>     success:function(reslove()){}<br>     error:function(){reject()}})<br>   })<br><br>}</pre><pre>getDataWithPromise().then(res=&gt;{data = res.data})</pre><h3>四、<strong>Promise與其他部分</strong></h3><h4><strong>一、加入async await</strong></h4><p>本篇三分鐘筆記Promise用法，後續使用可搭配 <a href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/async_function">async await</a> 讓Promise 寫法更加優雅?讓非同步也能像同步寫法那樣直觀，拿上面的getDataWithPromise 加入 async await 寫法</p><pre>//Promise + asyn await 寫法<br>let data<br>function getDataWithPromise(){...}</pre><pre>async function getAndSetData(){</pre><pre>    data = await getDataWithPromise()<br>}</pre><h4>二、非同步處理威力加強版</h4><p>平常處理非同步事件，其實Promise就能處理大多數案例，如果有更加複雜的就需要用到<a href="https://rxjs.dev/">Rxjs </a>了，也是個坑阿，改天有空來寫寫五分鐘rxjs使用好了。</p><h4><a href="https://jiahao831123.medium.com/%E7%9B%AE%E9%8C%84-4cbfef3d2ea9">文章目錄</a></h4><h3>Reference</h3><ul><li><a href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise - JavaScript | MDN</a></li><li><a href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/async_function">async function - JavaScript | MDN</a></li><li><a href="https://rxjs.dev/">RxJS</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b1a0ba711ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[vue2 composition api 認識]]></title>
            <link>https://jiahao831123.medium.com/vue2-composition-api-%E8%AA%8D%E8%AD%98-a81398415cf6?source=rss-fed3675a2c88------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81398415cf6</guid>
            <category><![CDATA[vue-2]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[vue-composition-api]]></category>
            <dc:creator><![CDATA[Jia]]></dc:creator>
            <pubDate>Fri, 22 Oct 2021 00:40:53 GMT</pubDate>
            <atom:updated>2021-10-26T02:55:37.772Z</atom:updated>
            <content:encoded><![CDATA[<p>2021.10.22</p><p>一些粗淺的筆記</p><p>Vue compostion-api</p><p><a href="https://v3.cn.vuejs.org/guide/composition-api-introduction.html#%E4%BB%80%E4%B9%88%E6%98%AF%E7%BB%84%E5%90%88%E5%BC%8F-api">官方文件</a></p><p>1.waht: compostion-api 是什麼</p><p>2.why: 為甚麼要用 compostion-api</p><p>3.how: 如何使用 compostion-api</p><p>4.other:vue2 使用compostion-api</p><h3>一、compostion-api 是什麼</h3><p>compostion-api 是vue3推出的新一項撰寫vue實體的方法。<br>舊有寫法稱為Oprion API，Compostion-api 是為了解決當模組過大而難以維護的情況而產生的。</p><h3>二、why: 為甚麼要用 compostion-api</h3><p>在vue2 時期，要解決單一vue實體過大通常會利用mixs來進行，但mixs有以下問題:</p><p>1.方法、資料等會被直接暴露在實體環境，可能會有重名問題<br>2.難以查明mixs方法來源，只能透過code style約束來追蹤<br>3.不能向mixs傳遞參數進行邏輯，大大降低可用性</p><p><a href="https://v3.cn.vuejs.org/guide/mixins.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E9%80%89%E9%A1%B9%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A5">misx不足，官方文件</a></p><p>因此vue3推出composition api來解決問題<br>此外 composition api 還有以下好處</p><ol><li>不再需要使用讓人疑惑的this。</li><li>可以透過es6 模組系統將自己撰寫的compostion api 在需要的時候動態載入</li></ol><p>3.可以傳入參數</p><h3>三、how: 如何使用 compostion-api</h3><p>1.使用vue3</p><p>2.使用vue2 使用官方提供的compostion-api <a href="https://github.com/vuejs/composition-api">擴充套件</a></p><h3>四、vue2 使用composiont api</h3><p>直接使用1.X 版會發生 computed 錯誤</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*ZsN52VC36yfIO24wt3jPcg.png" /></figure><p>這個問題要待解決，所以我目前只能使用0.X版的，以下是vue2 composition api cdn 的demo</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmisooncodepen%2Fembed%2Fpreview%2FPoKPjgZ%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DPoKPjgZ&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmisooncodepen%2Fpen%2FPoKPjgZ%3Feditors%3D1011&amp;image=https%3A%2F%2Fassets.codepen.io%2F1527900%2Finternal%2Fscreenshots%2Fpens%2FPoKPjgZ.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dfalse%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1634796240%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c89dcbf1a12e2652ad39b1e8741c0bb/href">https://medium.com/media/1c89dcbf1a12e2652ad39b1e8741c0bb/href</a></iframe><h4>2021.10.26 後續 問題解決</h4><p>今天發現，原來是vue版本的關係，從vue版本從2.0 升級到2.6 就解決了</p><p>今天學到了，使用套件要多注意本版 = =</p><p><a href="https://jiahao831123.medium.com/%E7%9B%AE%E9%8C%84-4cbfef3d2ea9">文章目錄</a></p><h3>Feference</h3><ul><li><a href="https://v3.vuejs.org/guide/composition-api-introduction.html">Introduction | Vue.js</a></li><li><a href="https://www.jianshu.com/p/94b9f60b56ec">vue3中的Composition API</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81398415cf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>