IT |
気になる、記になる… |
2022年8月のWebブラウザやOSのシェア |
https://taisy0.com/2022/09/02/160851.html
|
statcounter |
2022-09-01 15:31:09 |
AWS |
AWS Startups Blog |
From idea to app: build your MVP or prototype at the AWS Amplify September hackathon |
https://aws.amazon.com/blogs/startups/from-idea-to-app-build-your-mvp-or-prototype-at-the-aws-amplify-september-hackathon/
|
From idea to app build your MVP or prototype at the AWS Amplify September hackathonBring your idea to lifeーjoin the AWS Amplify hackathon hosted throughout September by Hashnode and Amazon Web Services AWS and start building your application |
2022-09-01 15:41:19 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
Poetry1.2 のリリースで個人的に重要であったこと、既存環境で加えた変更 |
https://qiita.com/nassy20/items/fbfa851e167f2fe7eefe
|
poetry |
2022-09-02 00:51:27 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
DjangoでCeleryとRedisを使って非同期処理 |
https://qiita.com/orc_jj/items/7d9cb57afe77d204c94e
|
pipinstallce |
2022-09-02 00:26:39 |
技術ブログ |
Developers.IO |
ジョブ・クラフティングで自ら仕事を「たーのしー!」な状態にする |
https://dev.classmethod.jp/articles/enjoy-work-by-job-crafting/
|
自分 |
2022-09-01 15:37:33 |
海外TECH |
DEV Community |
Adding a Soul into a React-Redux Project |
https://dev.to/simprl/adding-a-soul-into-a-react-redux-project-524b
|
Adding a Soul into a React Redux ProjectImaging we have React for UI and Redux for store data Users see a button click on it redux action happens data stored in the global redux state and button change visual style This looks like just a cause and an effect It feels lifeless Such applications are similar to primitive species Another thing a button that after clicking waits for a second simulating the thought process and then changes the UI And then waits one more second and turns itself off In this article I will try to explain how to add a brain into an application and making it smarter You can call this as “adding a Soul to a React Redux project I call it “Ghost in the React User interact with React components React components call actions Reducer change state in the Redux Now the Ghost comes into play Ghost sees that the state has changed and does some work and calls actions to save the result in the Redux React components see that state changed and show an updated UI to the user Step Install react with typescriptnpx create react app rg example template typescriptYou can find a lot of tutorials about So go to next step Step Prepear page Let s clean up file App tsx import React createContext useContext useMemo useState from react import App css type ContextInterface state boolean setState state boolean gt void const Context createContext lt ContextInterface gt state false setState state boolean gt undefined const App gt const state setState useState false const contextValue useMemo gt state setState state return lt Context Provider value contextValue gt lt Panel gt lt Context Provider gt const Panel gt const state setState useContext Context return lt div className App gt lt button onClick gt setState state gt state disable enable lt button gt lt span gt state enabled disabled lt span gt lt div gt export default App We added the button When click state change and button just change a text Step Adding a Ghost const ButtonGhost gt const state setState useContext Context useEffect gt if state const id setTimeout gt setState false return gt clearTimeout id state setState return null const App gt const state setState useState false const contextValue useMemo gt state setState state return lt Context Provider value contextValue gt lt Panel gt lt ButtonGhost gt lt Context Provider gt That s it If you run this code you ve already seen alive panel You click enable and it changes the state to enabled After second Ghost changes state back to disabled Step Time to add redux Before we store state using the React Context and hook useState Let s move the panel state to the Redux At first install packages npm i redux reduxjs toolkit use store pathI don t like the react redux package because I don t need all the functionality of this package It s enough for me just subscribe to state change So I use use store path instead import React createContext useContext useEffect from react import createSlice configureStore from reduxjs toolkit import type PayloadAction from reduxjs toolkit import getUseStorePath from use store path import App css export const stateSlice createSlice name flag initialState false reducers set state action PayloadAction lt boolean gt gt action payload const store configureStore reducer stateSlice reducer const exStore store useStorePath getUseStorePath store const Context createContext exStore const App gt lt Context Provider value exStore gt lt Panel gt lt ButtonGhost gt lt Context Provider gt const Panel gt const useStorePath dispatch useContext Context const flag useStorePath return lt div className App gt lt button onClick gt dispatch stateSlice actions set flag gt flag disable enable lt button gt lt span gt flag enabled disabled lt span gt lt div gt const ButtonGhost gt const useStorePath dispatch useContext Context const flag useStorePath useEffect gt if flag const id setTimeout gt dispatch stateSlice actions set false return gt clearTimeout id flag dispatch return null export default App Please note that in this article we only store one flag to simplify the examples In a real project each reducer will have more values and actions Step Dynamic reducer Dynamic reducer is very useful in a large application I use package simprl dynamic reducer for it npm i simprl dynamic reducerAdd useReducer hook to the application Contextimport reducer as dynamicReducer from simprl dynamic reducer import Reducer from redux const reducer addReducer dynamicReducer before const store configureStore reducer stateSlice reducer const store configureStore reducer const useReducer name string reducer Reducer gt useEffect gt addReducer name reducer store dispatch name reducer const exStore store useStorePath getUseStorePath store useReducer Now we can dynamically create reducer in the Ghost using useReducer We just need every time define a space flag when dispatch action and subscribe to the Redux store const ButtonGhost gt useReducer flag stateSlice reducer const useStorePath dispatch useContext Context const flag useStorePath flag useEffect gt if flag const id setTimeout gt dispatch stateSlice actions set false space flag return gt clearTimeout id flag dispatch return null Step Many spaces Now we can reuse same reducer in two spaces flag and flag const App gt lt Context Provider value exStore gt lt Panel space flag gt lt Panel space flag gt lt ButtonGhost space flag gt lt ButtonGhost space flag gt lt Context Provider gt type WithSpace space string const Panel space WithSpace gt const useStorePath dispatch useContext Context const flag useStorePath space return lt div className App gt lt button onClick gt dispatch stateSlice actions set flag space gt flag disable enable lt button gt lt span gt flag enabled disabled lt span gt lt div gt const ButtonGhost space WithSpace gt useReducer space stateSlice reducer const useStorePath dispatch useContext Context const flag useStorePath space useEffect gt if flag const id setTimeout gt dispatch stateSlice actions set false space return gt clearTimeout id flag dispatch return null export default App Button Component and Ghost can work with different spaces So we can reuse button ghost and reducer with the same functionality but for different space in the Redux Step Click handler But that is not all You might have noticed that we always recreate pointer to the click function It leads to a rerender memoized component because we put a new property each time Usually it fix by useCallbackconst Panel space WithSpace gt const useStorePath dispatch useContext Context const flag useStorePath space const clickHandler useCallback gt dispatch stateSlice actions set flag space space flag return lt div className App gt lt button onClick clickHandler gt flag disable enable lt button gt lt span gt flag enabled disabled lt span gt lt div gt But you can see property flag and space in the deps So we still have similar problem On each click this flag property changes and we again recreate function Actually pointer to the handler should not depends from flag and space properties But when handler call we need to get values of these properties from the last render I use hook useConstHandler from package use constant handlernpm i use constant handlerimport useConstHandler from use constant handler const clickHandler useConstHandler gt dispatch stateSlice actions set flag space useConstHandler every time returns a constant pointer to the function but the context of this function changes every render it means all properties in this function are always actual Step useAction hook Usually in my projects I create hook for call action const useSpaceAction space string actionCreator gt AnyAction gt useConstHandler gt store dispatch space actionCreator const exStore store useStorePath getUseStorePath store useReducer useSpaceAction Now Panel component look like thisconst Panel space WithSpace gt const useStorePath useSpaceAction useContext Context const flag useStorePath space const clickHandler useSpaceAction space gt stateSlice actions set flag return lt div className App gt lt button onClick clickHandler gt flag disable enable lt button gt lt span gt flag enabled disabled lt span gt lt div gt Step Separation into UI and business logic Good practice is separate UI and business logic Let s do it const App gt lt Context Provider value exStore gt lt div className App gt lt AppUi gt lt div gt lt AppGhost gt lt Context Provider gt Now we have two laysers of the application AppUi for UIAppGhost for business logicLet s implement them and add more interactivityconst AppGhost gt const useStorePath useContext Context const flag useStorePath flag return lt gt lt ButtonGhost space flag gt flag amp amp lt ButtonGhost space flag gt lt gt const AppUi gt const useStorePath useContext Context const flag useStorePath flag return lt gt lt Panel space flag gt flag amp amp lt Panel space flag gt lt gt Second panel and ghost render only if flag true Note that this is also an example of the advantage of a dynamic reducer Reducer for flag will add only if flag is true and will remove when flag false Step Don t use JSX for business logic Using JSX look strange for business logic We can get confused if we use JSX in both cases We need to somehow distinguish the business logic code from the UI code I suggest to use the keywords ghost and ghosts import createElement Fragment from react const ghost createElement const ghosts children gt createElement Fragment null children To standardize this I use the same package react ghost in all my projects npm i react ghostLets rewrite AppGhost without jsximport ghost ghosts from react ghost const AppGhost gt const useStorePath useContext Context const flag useStorePath lt boolean gt flag return ghosts ghost ButtonGhost space flag flag amp amp ghost ButtonGhost space flag ResultEntire file import React createContext useContext useEffect from react import createSlice configureStore AnyAction from reduxjs toolkit import type PayloadAction from reduxjs toolkit import reducer as dynamicReducer from simprl dynamic reducer import getUseStorePath from use store path import App css import Reducer from redux import useConstHandler from use constant handler import ghost ghosts from react ghost export const stateSlice createSlice name flag initialState false reducers set state action PayloadAction lt boolean gt gt action payload const reducer addReducer dynamicReducer const store configureStore reducer const useReducer name string reducer Reducer gt useEffect gt addReducer name reducer store dispatch name reducer const useSpaceAction space string actionCreator gt AnyAction gt useConstHandler gt store dispatch space actionCreator const exStore store useStorePath getUseStorePath store useReducer useSpaceAction const Context createContext exStore const App gt lt Context Provider value exStore gt lt div className App gt lt AppUi gt lt div gt lt AppGhost gt lt Context Provider gt type WithSpace space string const Panel space WithSpace gt const useStorePath useSpaceAction useContext Context const flag useStorePath space const clickHandler useSpaceAction space gt stateSlice actions set flag return lt div gt lt button onClick clickHandler gt flag disable enable lt button gt lt span gt flag enabled disabled lt span gt lt div gt const ButtonGhost space WithSpace gt useReducer space stateSlice reducer const useStorePath dispatch useContext Context const flag useStorePath space useEffect gt if flag const id setTimeout gt dispatch stateSlice actions set true space return gt clearTimeout id flag dispatch return null const AppUi gt const useStorePath useContext Context const flag useStorePath flag return lt gt lt Panel space flag gt flag amp amp lt Panel space flag gt lt gt const AppGhost gt const useStorePath useContext Context const flag useStorePath lt string gt flag return ghosts ghost ButtonGhost space flag flag amp amp ghost ButtonGhost space flag export default App You can play with this in codesandbox Source codeSource code is available on githubYou can check each step in the commit history FAQ Why don t you just use redux middleware your own or Thunk or Saga Middleware doesn t have hooks Why don t you just use hooks instead of ghost Hooks can t have conditions You cannot make a dynamic composition of hooks So while it is not a problem you can use hooks |
2022-09-01 15:35:09 |
Apple |
AppleInsider - Frontpage News |
Razer unveils new Kishi gaming controller for iPhone |
https://appleinsider.com/articles/22/09/01/razer-unveils-new-kishi-gaming-controller-for-iphone?utm_medium=rss
|
Razer unveils new Kishi gaming controller for iPhoneRazer has released an updated version of its Kishi gaming controller for iPhones with an improved design and a new app for customization Razer Kishi V gaming controller for iPhoneRazer s new controller is compatible with iPhone product lines going all the way back to the iPhone s and iPhone s Plus to bring as many iPhone gamers as possible into the Razer ecosystem AppleInsider reviewed the first Kishi controller in giving it a favorable score that makes it a great controller for Apple Arcade Read more |
2022-09-01 15:52:44 |
Apple |
AppleInsider - Frontpage News |
How to get the most from the Calendar app in iOS |
https://appleinsider.com/inside/ios/tips/how-to-get-the-most-from-the-calendar-app-in-ios?utm_medium=rss
|
How to get the most from the Calendar app in iOSThe Calendar app in iOS has many helpful tools and features that are hidden just below the surface Here s how to find them and get the most out of the app Apple s calendar app has been around since the beginning It s almost unrecognizable from how it launched though As with everything else Apple has made it simple to get started with with increasing depth the farther you look into it Here s how to get started and some features you may not know existed Read more |
2022-09-01 15:05:02 |
Cisco |
Cisco Blog |
Cisco Partners, Ready to Secure the Enterprise? |
https://blogs.cisco.com/partner/cisco-partners-ready-to-secure-the-enterprise
|
Cisco Partners Ready to Secure the Enterprise Change is constant As a Cisco Partner are you ready to help your customers achieve greater security resilience Learn how you can get started and generate demand while helping customers secure their enterprise |
2022-09-01 15:00:53 |
海外科学 |
NYT > Science |
California Approves a Wave of Aggressive New Climate Measures |
https://www.nytimes.com/2022/09/01/climate/california-lawmakers-climate-legislation.html
|
nuclear |
2022-09-01 15:40:22 |
金融 |
RSS FILE - 日本証券業協会 |
株券等貸借取引状況(週間) |
https://www.jsda.or.jp/shiryoshitsu/toukei/kabu-taiw/index.html
|
貸借 |
2022-09-01 15:30:00 |
金融 |
RSS FILE - 日本証券業協会 |
新型コロナウイルス感染症への証券関係機関等・各証券会社の対応について(リンク集) |
https://www.jsda.or.jp/shinchaku/coronavirus/link.html
|
新型コロナウイルス |
2022-09-01 15:10:00 |
金融 |
JPX マーケットニュース |
[東証]監理銘柄(確認中)の指定:(株)ダイオーズ |
https://www.jpx.co.jp/news/1023/20220902-11.html
|
監理銘柄 |
2022-09-02 00:35:00 |
金融 |
金融庁ホームページ |
つみたてNISA取扱金融機関一覧について更新しました。 |
https://www.fsa.go.jp/policy/nisa2/about/tsumitate/target/index.html
|
対象商品 |
2022-09-01 17:00:00 |
金融 |
金融庁ホームページ |
ペッツベスト少額短期保険株式会社に対する行政処分について公表しました。 |
https://www.fsa.go.jp/news/r4/hoken/20220901.html
|
少額短期保険 |
2022-09-01 17:00:00 |
ニュース |
BBC News - Home |
Olivia Pratt-Korbel: Police release footage of fleeing gunman |
https://www.bbc.co.uk/news/uk-england-merseyside-62668563?at_medium=RSS&at_campaign=KARANGA
|
korbel |
2022-09-01 15:56:24 |
ニュース |
BBC News - Home |
Putin will not attend Gorbachev's funeral |
https://www.bbc.co.uk/news/world-europe-62756196?at_medium=RSS&at_campaign=KARANGA
|
funeral |
2022-09-01 15:54:19 |
ニュース |
BBC News - Home |
Rail workers to stage two days of fresh strikes, RMT union says |
https://www.bbc.co.uk/news/business-62757431?at_medium=RSS&at_campaign=KARANGA
|
september |
2022-09-01 15:56:29 |
ニュース |
BBC News - Home |
Dutch Grand Prix: Red Bull could be embarking on era of domination, says Lewis Hamilton |
https://www.bbc.co.uk/sport/formula1/62756612?at_medium=RSS&at_campaign=KARANGA
|
mercedes |
2022-09-01 15:03:46 |
北海道 |
北海道新聞 |
札幌六大学野球 東海大札幌がコールド負け |
https://www.hokkaido-np.co.jp/article/725117/
|
六大学野球 |
2022-09-02 00:24:00 |
北海道 |
北海道新聞 |
コンサドーレの野々村前会長が“全国行脚”達成 58クラブ巡り札幌へ |
https://www.hokkaido-np.co.jp/article/725116/
|
運営会社 |
2022-09-02 00:21:00 |
北海道 |
北海道新聞 |
コンサドーレ札幌 金子復帰へ手応え十分 |
https://www.hokkaido-np.co.jp/article/725113/
|
降格圏 |
2022-09-02 00:17:00 |
北海道 |
北海道新聞 |
日本ハム浅間が右足骨折 今季復帰は絶望 |
https://www.hokkaido-np.co.jp/article/725110/
|
日本ハム |
2022-09-02 00:16:00 |
北海道 |
北海道新聞 |
不適切会計処理問題、ダイイチが防止策公表 |
https://www.hokkaido-np.co.jp/article/725107/
|
会計処理 |
2022-09-02 00:05:00 |
北海道 |
北海道新聞 |
大手、ビール回帰へ 酒税法改正で段階的減税 主力一新、新商品も続々 |
https://www.hokkaido-np.co.jp/article/725106/
|
酒税法 |
2022-09-02 00:04:00 |
北海道 |
北海道新聞 |
大丸札幌に人気のグリル店オープン |
https://www.hokkaido-np.co.jp/article/725105/
|
飲食店 |
2022-09-02 00:04:00 |
北海道 |
北海道新聞 |
女性会社員殺害容疑の養子が死亡 真相解明遠のく、大阪 |
https://www.hokkaido-np.co.jp/article/725103/
|
大阪府高槻市 |
2022-09-02 00:03:00 |
コメント
コメントを投稿