Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Smart Nano Stores, or how we made front-end sim...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nina Torgunakova
November 09, 2023
Programming
730
1
Share
Smart Nano Stores, or how we made front-end simpler (for the FOF meetup in Lisbon)
Nina Torgunakova
November 09, 2023
More Decks by Nina Torgunakova
See All by Nina Torgunakova
Smart nano stores for state management, or how we made front-end simpler
ninoid
0
1.1k
Unveiling Nano Stores
ninoid
0
990
Умные nano stores, или как мы сделали веб-разработку проще
ninoid
0
990
Solving algorithms: beyond cramming for job interviews
ninoid
0
2.2k
Other Decks in Programming
See All in Programming
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
360
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
190
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
470
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.8k
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
2.2k
Agentic Elixir
whatyouhide
0
440
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
1
640
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
130
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
4
410
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
150
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
210
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
620
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
610
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Paper Plane
katiecoart
PRO
1
49k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
The Curse of the Amulet
leimatthew05
1
12k
Chasing Engaging Ingredients in Design
codingconduct
0
180
Faster Mobile Websites
deanohume
310
31k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
210
HDC tutorial
michielstock
2
650
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
350
Google's AI Overviews - The New Search
badams
0
1k
Transcript
Smart nano stores for state management 1 @evilmartians or how
we made front-end simpler
Nina Torgunakova Frontend Engineer 2 @evilmartians
3 @evilmartians What we had before
4 What we have today * Source: www.medium.com/@withinsight1/the-front-end-spectrum-c0f30998c9f0/ @evilmartians
The modern Web Development World is becoming more and more
complex. Who suffers from it? 5 @evilmartians
1. Developers 6 @evilmartians
7 Everything is built around frameworks but remains complex @evilmartians
2. Users 8 @evilmartians
The average size of web pages is constantly growing up
9 * Source: www.keycdn.com/support/the-growth-of-web-page-size @evilmartians
3. Business 10 @evilmartians
11 Often, to do the same amount of work, more
programmers are needed. Now Before @evilmartians
12 Result: the growing complexity of Web Development makes everyone
frustrated Users Developers Business @evilmartians
13 Let's try to find inspiration! @evilmartians
Fold knowledge into data, so program logic can be stupid
and robust. 14 Eric Raymond, “Rule of Representation” @evilmartians
15 Framework Logic UI Features Data @evilmartians
But what if we made a mistake? 16 @evilmartians
17
None
19 Data Logic UI Features @evilmartians Framework Logic UI Features
Data Framework
State Management 20 Application Data State @evilmartians
21 Use stores to move logic outside of components @evilmartians
Component Component Component Store Store
OK, any other ideas about the ideal process of state
management? 22 @evilmartians
Bad programmers worry about the code. Good programmers worry about
data structures and their relationships. 23 Linus Torvalds @evilmartians
24 Global State Any State Change All Components Call the
selector function Popular global state approach: @evilmartians
25 How about improving data structure and making it faster?
@evilmartians
26 Reactive programming approach: @evilmartians
27 Applying to State Management: Component Component Component Subscriber 1
Subscriber 2 Subscriber 3 @evilmartians Small Store Small Store Small Store
28 But what if some data depends on other data?
@evilmartians
29 Solution: Relationships between stores Store Store Store Store @evilmartians
Component Component
1. Move logic to stores outside of component 2. Make
stores small and smart Let's go further! 30 @evilmartians
Perfection is achieved, not when there is nothing more to
add, but when there is nothing left to take away. 31 Antoine de Saint-Exupéry @evilmartians
32 @evilmartians State Management in modern frameworks
33 Smart Store Set value Get value @evilmartians
34 Let's summarize! @evilmartians
1. Move logic to stores outside of components. 35 Component
Component Component Store Store @evilmartians
2. Make stores smart. 36 Store Store Store Store @evilmartians
Store Component Component
3. Provide minimalism and simplicity. 37 Store One-line operations: •
Create store • Get value • Set value @evilmartians Get value Set value
38 ??? What state manager will solve all the problems?
@evilmartians
39 Nano Stores @evilmartians
Let's build a simple online catalog: 40 @evilmartians
41 @evilmartians
Creating atom store for products in catalog: // core/state.ts import
{ atom } from 'nanostores'; export const $products = atom<Product[]>([ { name: 'Nano Phone', price: 30 }, { name: 'Nano TV', price: 75 }, { name: 'Nano Laptop', price: 75 } ]); 42 @evilmartians
Using atom store: // components/Catalog.tsx import { useStore } from
'@nanostores/react'; import { $products } from 'core/state'; const Catalog = () => { const products = useStore($products); return <>{products.map((product) => <Card product={product} />)}</>; }; 43 @evilmartians
44 @evilmartians
Adding filtering using search input 45 @evilmartians
Creating atom store for search input: // core/state.ts import {
atom } from 'nanostores'; export const $searchInput = atom<string>(''); 46 @evilmartians
Using atom store for search input: // components/SearchBar.tsx import {
useStore } from '@nanostores/react'; import { $searchInput } from 'core/state'; const SearchBar = () => { const searchInput = useStore($searchInput); return <input onChange={(e) => $searchInput.set(e.target.value)} value={searchInput} />; }; 47 @evilmartians
Adding computed store to filter catalog: // core/state.ts import {
computed } from 'nanostores'; export const $filteredProducts = computed( [$searchInput, $products], (searchInput, products) => { return products.filter(product => product.name.includes(searchInput)); } ); 48 @evilmartians
Using computed store in components: // components/Catalog.tsx import { useStore
} from '@nanostores/react'; import { $filteredProducts } from 'core/state'; // Usage is exactly the same: const Catalog = () => { const filteredProducts = useStore($filteredProducts); return <>{filteredProducts.map((product) => <Card product={product} />)}</>; }; 49 @evilmartians
50 @evilmartians
So, what is next? 1. Try out a new approach
to state management in your own project. 2. See the power of simplicity! 51 @evilmartians github.com/nanostores
ninaTorgunakova 52 @evilmartians Questions? github.com/nanostores