dmitriid
Joined 18 years ago
Joined 18 years ago
What are you on about? Redux is literally about global state everywhere. But with three to four layers of abstractions between.
You define your state globally. Then use hooks to fetch data from that global state, and then "dispatch" aka call actions on that global state. If something else somewhere else updates data in that global state your component will be affected if it uses that data.
But it also requires you to write an insane amount of useless stuff like "define your store, then reducers, then slices, then god knows what" to arrive at almost the same code:
// redux
import { useSelector, useDispatch } from 'react-redux'
import { decrement, increment } from './counterSlice'
export function Counter() {
// note how we reach into magical global state that useSelector knows about
const count = useSelector((state: RootState) => state.counter.value)
const dispatch = useDispatch()
return <>
<button onClick={() => dispatch(increment())}>Increment</button>
<span>{count}</span>
<button onClick={() => dispatch(decrement())}>Decrement</button>
</>;
}
// solid
// state is immutable. It's also not magical, you explicitly refrence and import it
//
// increment and decrement would use a `set` function to update the store to required value
// see https://www.solidjs.com/docs/latest/api#createstore
// and https://www.solidjs.com/docs/latest/api#updating-stores
//
import { state, increment, decrement } from './counter-store';
export function Counter() {
return <>
<button onClick={() => increment()}>Increment</button>
<span>{state.count}</span>
<button onClick={() => decrement()}>Decrement</button>
</>;
}And you never use only local state. You advocate for Redux in a different comment which is literally a global state where you are going to have something suddenly change somewhere from the point of view of a component.
Let's see:
--- start quote ---
A gun in the Czech Republic is available to anybody subject to acquiring a firearms license. Gun licenses may be obtained in a way similar to a driving license – by passing a gun proficiency exam, medical examination and having a clean criminal record.
the issuing authority (police) firearm owners' database is connected to information needed for a background check and red flags any incidents that may lead to loss of license requirements. Similarly, health clearance by the general practitioner is needed for periodical renewal of license (every ten years).
* also very specific restrictions depending on license *
Obtaining the license requires passing a theoretical and practical exam.
https://en.wikipedia.org/wiki/Gun_law_in_the_Czech_Republic
--- end quote ---
Oh look, already more strict than many states in the US (and some states are busy removing any restrictions).
Let's say you're a teacher with known dissident tendencies. Boom. Suddenly the only place you can get work is one of these remote regions with lax control. Yes there is less government there, and you can even start a book club or something to read and discuss banned literature, and no one will bother you.
But try and get out because you're tired of rural life... and no place in the "mainland" will acept you. Or will only offer you menial jobs and unskilled labor.
This was a very widely and well-used tactic in the USSR. Can't see why China (or any other authoritatian state) wouldn't do the same. Especially China with their current state of surveillance tech.
Strange that you don't like spaghetti, but then praise Redux that is spaghetti exemplified: dozens of functions, and wrappers, and hooks eerywhere. Trying to trace how a value gets changed through the three-four layers of wrappers is like pulling teeth through the anus.
And looking at the current reincarnation of this abomination, it is marginally less spaghetti, and converging on the same signals code that everyone is converging on.
- The Evolution of Signals in JavaScript, https://dev.to/this-is-learning/the-evolution-of-signals-in-...
- React vs Signals: 10 Years Later, https://dev.to/this-is-learning/react-vs-signals-10-years-la...
- Making the Case for Signals in JavaScript , https://dev.to/this-is-learning/making-the-case-for-signals-...
Those two code examples are different because that's the tradeoff that Solid made. It allows Solid to track changes in a uniform way even if the data isn't inside a component. Because in Solid components are just a way to organize code, not a unit of rendering (like in React).
And on top of that if you think that React still somehow has unidirectional data flow, it doesn't. Hooks make it anything but unidirectional. And not that different from signals: https://res.cloudinary.com/practicaldev/image/fetch/s--upMC6... But often less predictable.
See also The Cost of Consistency in UI Frameworks, https://dev.to/this-is-learning/the-cost-of-consistency-in-u... which is slightly related to this.
Because new buildings these days are invariably the same boring gray dull shit that robs any place of its identity?