投稿時間:2023-03-20 16:17:00 RSSフィード2023-03-20 16:00 分まとめ(21件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Techable(テッカブル) 覗き見を防止!Dynamic Islandに干渉しないiPhone14用ガラスフィルム発売 https://techable.jp/archives/200711 dynamicisland 2023-03-20 06:00:44
IT 情報システムリーダーのためのIT情報専門サイト IT Leaders 富士通、識別性能の低下なく画像識別AIを修正する技術を開発、自動車画像データで有効性を確認 | IT Leaders https://it.impress.co.jp/articles/-/24601 富士通、識別性能の低下なく画像識別AIを修正する技術を開発、自動車画像データで有効性を確認ITLeaders富士通は年月日、画像識別AIを修正する技術を開発したと発表した。 2023-03-20 15:44:00
AWS AWSタグが付けられた新着投稿 - Qiita 自チームでクラウドを対応することになったリーダー/管理職へ(学習方法) https://qiita.com/yhotta/items/11832aa8e8635c7c808f 試行錯誤 2023-03-20 15:37:31
AWS AWSタグが付けられた新着投稿 - Qiita 自チームでクラウドを対応することになったリーダー/管理職へ(なぜAWS?) https://qiita.com/yhotta/items/c975ee111229470238d0 試行錯誤 2023-03-20 15:37:19
AWS AWSタグが付けられた新着投稿 - Qiita 自チームでクラウドを対応することになったリーダー/管理職へ(はじめに) https://qiita.com/yhotta/items/c55c8c7e19462cede498 試行錯誤 2023-03-20 15:37:03
AWS AWSタグが付けられた新着投稿 - Qiita PostgreSql dump取得コマンド https://qiita.com/ma_3636/items/970043585ed54bc1eab0 pemubu 2023-03-20 15:35:59
Docker dockerタグが付けられた新着投稿 - Qiita PostgreSql dump取得コマンド https://qiita.com/ma_3636/items/970043585ed54bc1eab0 pemubu 2023-03-20 15:35:59
技術ブログ Developers.IO 元トレーナーがChatGPTのダイエットアドバイスを評価してみた(Web版ChatGPT) https://dev.classmethod.jp/articles/chatgpt-with-trainer/ chatgpt 2023-03-20 06:47:12
海外TECH DEV Community Reusable component store for pagination using generics https://dev.to/this-is-angular/reusable-component-store-for-pagination-using-generics-1na6 Reusable component store for pagination using genericsIn the last article we created a component store using NgRx to handle the pagination of todo itemsUnfortunately this approach is very specific to our domain and it is now time for us to look for a reusable solution that we can slap on another entity that we would like to paginate the same way Table of contentCreating our new storeThe stateThe store itselfSetting the foundationsCreating selectorsHandling paginationUsing NgRx lifecycle hooksIntroducing genericsRework our stateUpdating our storeUpdating our state Creating our new storeLet s begin by creating a new paginated items component store ts file where our pagination logic will take place The stateBefore defining our store we will first have to focus on its stateHere is our state in its current form export interface AppState todoItems TodoItem offset number pageSize number We can divide its properties into two main categories Everything related to the pagination offset pageSize Everything related to the items themselves only todoItems in our case From this we can extract a subsequent interface which has the responsibility of wrapping the parameters related to the pagination export interface PaginationDetails offset number pageSize number And another one which will wrap the content of the page export interface PageContent todoItems TodoItem Using these two interfaces we now have a state that is a bit more explicit export interface PaginatedItemsState paginationDetails PaginationDetails pageContent PageContent Great let s move on The store itself Setting the foundationsThis store will be defined as an abstract class so that each subsequent store can add its own logic to is Using the previously defined state we can write this Injectable Beware not to forget the abstract hereexport abstract class PaginatedItemsComponentStore extends ComponentStore lt PaginatedItemsState gt Creating selectorsHaving state management is great being able to access its content is better let s add some selectors We can start by adding some base ones to retrieve each property Injectable export abstract class PaginatedItemsComponentStore extends ComponentStore lt PaginatedItemsState gt readonly selectPaginatedItemsState this select state gt state readonly selectPaginationDetails this select this selectPaginatedItemsState paginationDetails gt paginationDetails readonly selectOffset this select this selectPaginationDetails offset gt offset readonly selectPageSize this select this selectPaginationDetails pageSize gt pageSize readonly selectPageContent this select this selectPaginatedItemsState pageContent gt pageContent readonly selectTodoItems this select this selectPageContent todoItems gt todoItems That s a lot of selectors but keep in mind that the purpose of this store is to be flexible enough so that any store that inherits from it can use those internals instead of rewriting them somewhere else Handling paginationFrom our store let s add some updaters to update our state Injectable export abstract class PaginatedItemsComponentStore extends ComponentStore lt PaginatedItemsState gt Selectors omitted here private readonly updatePagination this updater state paginationDetails PaginationDetails gt state paginationDetails private readonly updatePaginatedItems this updater state pageContent PageContent gt state pageContent I will be using one for the pagination and one for the paginated items but feel free to be more or less granular if you want to Finally we can copy paste and adapt a bit our two previous loadPage and loadNextPage effects from our AppComponentStore Injectable export abstract class PaginatedItemsComponentStore extends ComponentStore lt PaginatedItemsState gt Selectors omitted here Don t forget to also inject our service private readonly todoItemService inject TodoItemService readonly loadPage this effect trigger Observable lt void gt gt return trigger pipe We can directly access our pagination details from our selector withLatestFrom this selectPaginationDetails switchMap offset pageSize gt this todoItemService getTodoItems offset pageSize pipe tapResponse todoItems TodoItem gt this updatePaginatedItems todoItems gt console error Something went wrong readonly loadNextPage this effect trigger Observable lt void gt gt return trigger pipe Same here withLatestFrom this selectPaginationDetails tap offset pageSize gt this updatePagination offset offset pageSize pageSize tap gt this loadPage Updaters omitted here Using NgRx lifecycle hooksAs we did in our first version we can also take advantage of the OnStoreInit lifecycle hook here to load the page on startup Injectable export abstract class PaginatedItemsComponentStore extends ComponentStore lt PaginatedItemsState gt implements OnStoreInit ngrxOnStoreInit this loadPage By doing so we can ensure that each store paginating items and thus inheriting this one will load the first page upon creation Inheriting from our storeFinally all that is left to do is for our AppComponentStore to inherit from our PaginatedItemsComponentStore instead of ComponentStore lt AppState gt For that we need to change our initial state and get rid of our own AppState to use the provided PaginatedItemsState app component store tsconst initialState PaginatedItemsState paginationDetails offset pageSize pageContent todoItems Once this is done we can delete all updaters effects and lifecycle hooks implementations from our component store and use instead the logic of the PaginatedComponentStore Injectable export class AppComponentStore extends PaginatedItemsComponentStore readonly vm this select this selectTodoItems todoItems gt todoItems constructor super initialState If you run your application after this change everything should still be working as it was before yay Introducing genericsSo far so good but let s not rejoice so fastIf everything as been as easy as copying and pasting code from our former store to the new one it is only because we are constraining it to TodoItemsIn a regular application you may surely have more than one type of entity to paginateFortunately TypeScript handles generics pretty well and this is something we can leverage to increase the reusability of our PaginatedItemsComponentStore Rework our stateThe first place to look at is our PageContent interfaceIn this one we are defining the content as an array of TodoItem but we want to allow for a broader set of typesWe may be tempted to change it to any but since we are using Type Script and not Any Script we may find a better wayUsing generics we can specify to our interface that we would like to have an array of items whose type will be TItem since we don t know it yet export interface PageContent lt TItem gt Since we are manipulating items now I renamed the property items TItem By convention I m naming any generic type by starting with a T followed by its logical meaningUpdating this interface will need us to rewrite the PaginatedItemsState as well since we need to propagate the generics export interface PaginatedItemsState lt TItem gt paginationDetails PaginationDetails pageContent PageContent lt TItem gt Updating our storeWith the updates made to the state our store is no longer valid and we also need to propagate the generic type hereHowever we don t want to use a concrete type yet or all our modifications would have been done for nothingTo address the fist compilation error we will first need to also indicate our store that we will be using TItem Injectable export abstract class PaginatedItemsComponentStore lt TItem gt extends ComponentStore lt PaginatedItemsState lt TItem gt gt implements OnStoreInit After doing so there is two small errors we need to address In our selectTodoItems selector todoItems does no longer exists since we have rename it to items We can fix it by changing the property name readonly selectItems this select this selectPageContent items gt items In our updatePaginatedItems updated PageContent is not aware of the generic type and we need to specify it private readonly updatePaginatedItems this updater state pageContent PageContent lt TItem gt gt state pageContent However we now face a bigger issue in the loadPage effect we are calling the todoItemService and this service is very specific to our TodoItems Delegate the fetching logicFrom our PaginatedItemsComponentStore there is no way for us to know in advance how a specific kind of TItem will be retrieved given an offset and the page sizeHowever a class that will know that is the implementing oneFortunately we are in an abstract class and we can let the child class define its own logic by adding an abstract method protected abstract getItems paginationDetails PaginationDetails Observable lt TItem gt Using this method we can now remove the instance of our service and replace its call by the abstract method private readonly todoItemService inject TodoItemService readonly loadPage this effect trigger Observable lt void gt gt return trigger pipe withLatestFrom this selectPaginationDetails switchMap offset pageSize gt this todoItemService getTodoItems offset pageSize pipe this getItems offset pageSize pipe tapResponse todoItems TodoItem gt this updatePaginatedItems todoItems items TItem gt this updatePaginatedItems items gt console error Something went wrong Updating the AppComponentStoreWe re almost done Now that our base store is generic we need to specify in our AppComponentStore that TItem will be TodoItem for us Notice that we are now talking about TodoItem const initialState PaginatedItemsState lt TodoItem gt paginationDetails offset pageSize pageContent items Injectable export class AppComponentStore Same here extends PaginatedItemsComponentStore lt TodoItem gt readonly vm this select Don t forget that our selector has been renamed this selectItems todoItems gt todoItems However we now also need to implement that getItems method so that our parent component knows how to retrieve those TodoItemsFor that we will need to reinject a TodoItemService instance and call it from there private readonly todoItemService inject TodoItemService protected getItems offset pageSize PaginationDetails Observable lt TodoItem gt return this todoItemService getTodoItems offset pageSize Building our app again everything should still be working as before but this time paginating a new type of entity won t need you to rewrite the whole component store again In this article we saw how to take advantage of generics to lift the common pagination logic to an abstract component that we can later extendIf you would like to go a bit further you can try to Handle the loading and error logicAdd extra selectors first item of the page etc Create a new PostService that is almost the same as the TodoItemService except that it is retrieving posts by calling You can then use this service to paginate Posts instead of TodoItems by defining a new component store inheriting from PaginatedItemsComponentStore lt Post gt If you would like to check the resulting code you can head on to the associated GitHub repositoryI hope that you learnt something useful there and as always happy coding Pierre BouillonFollow Software Engineer Privacy Advocate Coffee Lover Photo by Roman Trifonov on Unsplash 2023-03-20 06:09:00
医療系 医療介護 CBnews コロナ新規入院、10歳代と40歳代で微増-感染研が第10週のコロナサーベイランス週報公表 https://www.cbnews.jp/news/entry/20230320124225 国立感染症研究所 2023-03-20 15:30:00
金融 JPX マーケットニュース [東証]TOKYO PRO Marketへの上場申請:(株)はなホールディングス https://www.jpx.co.jp/equities/products/tpm/issues/index.html tokyopromarket 2023-03-20 15:30:00
金融 JPX マーケットニュース [OSE]特別清算数値(2023年3月限):NYダウ https://www.jpx.co.jp/markets/derivatives/special-quotation/ 特別清算 2023-03-20 15:15:00
ニュース BBC News - Home Climate change: Couple set for Pole-to-Pole electric car challenge https://www.bbc.co.uk/news/uk-scotland-north-east-orkney-shetland-64964294?at_medium=RSS&at_campaign=KARANGA antarctica 2023-03-20 06:25:07
ニュース BBC News - Home Australian former SAS soldier Oliver Schulz held over alleged war crime in Afghanistan https://www.bbc.co.uk/news/world-australia-65010345?at_medium=RSS&at_campaign=KARANGA australian 2023-03-20 06:05:30
ニュース BBC News - Home Amritpal Singh: Punjab police intensifies search for controversial preacher https://www.bbc.co.uk/news/world-asia-india-65010808?at_medium=RSS&at_campaign=KARANGA khalistan 2023-03-20 06:48:45
ニュース BBC News - Home Iraq War: The helmet that saved a Black Watch soldier's life https://www.bbc.co.uk/news/uk-scotland-65008347?at_medium=RSS&at_campaign=KARANGA roadside 2023-03-20 06:25:35
ニュース BBC News - Home Miss Wales says she is grateful after life-changing M4 crash https://www.bbc.co.uk/news/uk-wales-64981797?at_medium=RSS&at_campaign=KARANGA january 2023-03-20 06:11:50
ニュース BBC News - Home Bukayo Saka: Arsenal "don't fear anyone" in Premier League title race https://www.bbc.co.uk/sport/av/football/65009136?at_medium=RSS&at_campaign=KARANGA Bukayo Saka Arsenal quot don x t fear anyone quot in Premier League title raceMatch of the Day talk to Bukayo Saka and analyse his two goals after a win over Crystal Palace with Saka stating Arsenal don t fear anyone in the title race 2023-03-20 06:39:48
ニュース Newsweek クレムリンはプーチンの後継者探しを始めている──プーチン抜きで https://www.newsweekjapan.jp/stories/world/2023/03/post-101151.php プーチンに批判的な人々のなかには、プーチンが今回の侵攻を「戦争」ではなく「特別軍事作戦」に分類し、軍が完全な動員を開始するための権限を制限したことを批判する声もある。 2023-03-20 15:24:53
IT 週刊アスキー 復活にして最後の開催! MIGHTY CROWN主催の「横浜レゲエ祭」が12年ぶりに横浜の野外に帰ってくる https://weekly.ascii.jp/elem/000/004/129/4129287/ mightycrown 2023-03-20 15:30:00
IT 週刊アスキー 『ライザのアトリエ』がアニメ化決定!放送は2023年の“夏” https://weekly.ascii.jp/elem/000/004/129/4129309/ 秘密 2023-03-20 15:30: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件)