投稿時間:2023-08-05 17:15:11 RSSフィード2023-08-05 17:00 分まとめ(15件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Techable(テッカブル) “その店舗ならでは”の文体でクチコミ返信文章をAIが自動提案!「STOREPAD」にAIアシスト機能β版追加 https://techable.jp/archives/215969 storepad 2023-08-05 07:00:30
python Pythonタグが付けられた新着投稿 - Qiita 【ゼロから独学】Python3エンジニア認定基礎試験勉強法 https://qiita.com/ysk_510/items/c5da0b0b14b0791b015f diveintocode 2023-08-05 16:52:17
js JavaScriptタグが付けられた新着投稿 - Qiita JavaScript超便利!一瞬で理解する分割代入のすべて https://qiita.com/itinerant_programmer/items/55c893703cd29a79c045 destructuringassi 2023-08-05 16:04:26
Ruby Rubyタグが付けられた新着投稿 - Qiita Railsチュートリアル6章まとめ https://qiita.com/qiita-oy/items/15b85817a85758be7334 activerecord 2023-08-05 16:28:27
AWS AWSタグが付けられた新着投稿 - Qiita Amazon EC2インスタンス作成の手順 https://qiita.com/hiro_10/items/3ee98a7842c3c74e0d29 amazon 2023-08-05 16:52:41
AWS AWSタグが付けられた新着投稿 - Qiita ECSコンテナ@Fargateにログインする際の躓きに関する備忘録 https://qiita.com/craftect/items/7c81c89e00f39e6c95ed fargate 2023-08-05 16:01:45
Docker dockerタグが付けられた新着投稿 - Qiita Webアプリケーションのためのdocker-compose.yml備忘録 https://qiita.com/nate3870/items/c6adbb13c3ac79371aa0 dockercomposeyml 2023-08-05 16:17:56
Ruby Railsタグが付けられた新着投稿 - Qiita Railsチュートリアル6章まとめ https://qiita.com/qiita-oy/items/15b85817a85758be7334 activerecord 2023-08-05 16:28:27
海外TECH DEV Community Frontend state management with clean architecture https://dev.to/oscarprdev/frontend-state-management-with-clean-architecture-22d8 Frontend state management with clean architecture INTRODUCCIONOne of the most critical aspects of developing a client side application is how we handle global state management Many developers spend hours and hours searching for the perfect tool Redux Akita Pinia Ngrx Context Vuex But the truth is if we aim for code that is agnostic and truly maintainable over time we cannot simply delegate the core piece of our applications to external libraries or tools whose future maintenance is uncertain That s where clean architecture comes to the rescue advising us to separate the domain or core components of our application from those parts that are likely to change over time In other words tools and frameworks should never directly manage any piece of the global state of our application So I ve taken the initiative to create this post and share my step by step solution on how to handle global domain state in a client side application using Typescript and Object Oriented Programming OOP Let s begin REACTIVITYWhen it comes to managing global state we need it to be reactive to any changes that occur within it Therefore if we are going to build a global state handler reactivity should be our top priority Let s create an abstract class that will solely take care of managing the global state with reactivity export abstract class UseCase lt S gt public state S private listeners Subscription lt S gt We will name the class UseCase and it will have two properties state and listeners state will be responsible for holding the global state while listeners will handle reactivity Our class will include a constructor that receives the state of the feature extending the use case constructor initialState S this state initialState Methods The first method of this class will be the one that allows us to execute any use case abstract execute value any voidAbsolutely right The first method should be abstract so that the extending class can handle any logic such as calling an API to fetch information On the other hand we also need a method to retrieve the state when required getState S return this state Exactly We need another method to update the state This will allow us to modify the global state when necessary updateState newState Partial lt S gt void this state this state newState Now here comes the magic where reactivity occurs intuitively and easy to understand We ll add a small piece of code to the updateState method that will execute any method found in the listeners property we created earlier Here s how the updateState method would look like updateState newState Partial lt S gt void this state this state newState if this listeners length this listeners forEach listener gt listener this state Now every time we want to update the state it will trigger a function to which we ll pass the updated state as an argument This will enable reactivity as any listeners registered with the listeners property will be notified and can react accordingly to the changes in the global state This approach simplifies the handling of reactivity and makes it intuitive and easy to manage listener this state To make the listeners property functional we need to introduce the methods we want it to execute We ll achieve this by adding another method called subscribe subscribe listener Subscription lt S gt this listeners push listener The subscribe method will allow us to add methods to the listeners property so that they can be executed when the state is updated This way we can dynamically register functions to react to state changes in our application Shall you guess which method we could pass to this subscribe method CUSTOM HOOKExactly Now that we have our abstract class we can use it anywhere in our code But how do we connect our fancy framework to our previous code Well there can be numerous solutions from here on and it all depends on the specific framework we re using For this example let s dive into React and create a custom hook Why not make it fun and enjoy the magic of connecting everything smoothly export default function useSubscription lt S U extends UseCase lt S gt gt useCase U setStateFn Dispatch lt SetStateAction lt S gt gt useCase execute useCase subscribe state gt setStateFn prevState gt prevState state The useSubscription custom hook allows us to call the execute method which can for instance make API calls and we can also use the subscribe method to pass a function that updates the state of our components setStateFn prevState gt prevState state With this magical useSubscription custom hook we can seamlessly connect our abstract class to React components and enjoy the wonders of reactivity Now every state update will trigger the registered functions ensuring our components stay in sync with the global state Isn t this a delightful way to handle state management Let the fun begin IMPLEMENTATIONNow that we ve reached this point let s see how we implement this custom hook in our React component Imagine an application for recipes and our component wants to fetch recipes from the database With React we d do something similar to this const listRecipes setListRecipes useState lt ListRecipesUseCaseState gt listRecipesUseCase getState We ll use useState to manage the state of recipe lists and we ll initiate it by calling the API with the method listRecipesUseCase getState Once again you got it Following this let s use useEffect to subscribe to our global state useEffect gt useSubscription lt ListRecipesUseCaseState ListRecipesUseCase gt listRecipesUseCase setListRecipes With the useEffect our component will subscribe to the global state changes ensuring it stays in sync with any updates that occur Now our recipe app is all set to whip up a delightful user experience SVELTE EXAMPLEFantastic To wrap it up let s illustrate the same implementation this time using Svelte In Svelte we ll create a store that exposes a method called setAppState which will update the state using the appState set state function export const appState writable stateUseCase state gt stateUseCase setDefaultState books export const setAppState state GlobalState gt appState set state To use this approach we ll call the subscribe method in our App svelte file Here s how it would look beforeUpdate gt stateUseCase subscribe setAppState This way our app will automatically subscribe and update the global state every time we call updateState in our use cases It creates a seamless and reactive experience keeping our app in sync with the global state effortlesslyThank you for joining me on this journey I hope this has been helpful and I look forward to your feedback Happy coding oscarprdev 2023-08-05 07:15:26
ニュース BBC News - Home Russia says tanker hit in Ukrainian attack near Crimea https://www.bbc.co.uk/news/world-europe-66412842?at_medium=RSS&at_campaign=KARANGA crimeathe 2023-08-05 07:35:37
ニュース BBC News - Home Switzerland 1-5 Spain: Aitana Bonmati scores twice as La Roja march into quarter-finals https://www.bbc.co.uk/sport/football/66404305?at_medium=RSS&at_campaign=KARANGA Switzerland Spain Aitana Bonmati scores twice as La Roja march into quarter finalsSpain reach the quarter finals of the Fifa Women s World Cup for the first time after producing an outstanding display of firepower to send Switzerland out 2023-08-05 07:22:48
ニュース BBC News - Home UK scouts pulling out of camp after S Korea heatwave https://www.bbc.co.uk/news/uk-66407392?at_medium=RSS&at_campaign=KARANGA jamboree 2023-08-05 07:28:29
ニュース BBC News - Home New Zealand 23-20 Australia: All Blacks fight back for dramatic win https://www.bbc.co.uk/sport/rugby-union/66414340?at_medium=RSS&at_campaign=KARANGA world 2023-08-05 07:14:00
ニュース BBC News - Home Marc Marquez: MotoGP great says 'some people around me say it is time to stop' https://www.bbc.co.uk/sport/motorsport/66406229?at_medium=RSS&at_campaign=KARANGA Marc Marquez MotoGP great says x some people around me say it is time to stop x MotoGP rider Marc Marquez on rebuilding his confidence to get back to championship winning ways after years of injuries and crashes 2023-08-05 07:16:37
ニュース Newsweek 「無数の火球」が都市に降り注ぐ...ウクライナで、カミカゼドローンが撃墜されるシーンを公開 https://www.newsweekjapan.jp/stories/world/2023/08/post-102362.php 日には、ロシア軍が夜間にロシア国境地帯のブリャンスク州から機の「シャヘド」を発射したと、ウクライナ軍が発表した。 2023-08-05 16:27:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)