Comments (3)
Yeah.. this is a functional convention I picked up from my time with RxJS. Essentially I wanted to create an extensible operator pattern that didn't require hoisting the Signals. For info on the idea look at Let-able or Pipe-able operators in RxJS.
In basic as you add more operators to the Signal object you need to wrap new versions or add methods to it's prototype. This is a mess if not all applications have the need for all the operators. So why the order? To make them functionally composable.
// classic example
signal.map(i=>i).filter(i=>i)
// not hoisted
filter(map(signal, i => i), i => i)
// composable
filter(i => i)(map(i => i)(signal))
However the latter 2 examples lose the sequential order of operations. However, as you can see operators reduce right in the last example which lets you write it as:
compose(
map(i => i),
filter(i => i)
)(signal)
This returns to the sequential order. I've included a pipe operator which lets you write it as:
pipe(
signal,
map(i => i),
filter(i => i)
)
So I could also export non-pipeable operators, but they do come with a few really nice benefits. Like you can create new operators by composing existing ones, or by applying arguments to existing.
const double = map(i => i * 2);
// somewhere else...
const doubledSignal = double(signal);
The operators sections gives some examples.
from solid.
I didn't finish my thought here. So to your example you can use pipe.
pipe(() => props.state.todos.length > 0, when(() => <TodoFooter {...props} />))
The operator naming perhaps needs work.. When suggests condition and Each suggests the iterated, when in fact both are just the mapping function.
For single operators I tend to not use pipe since the args are flat enough.
I might be weighing the importance of extendability too far. But Signals are a lot like simpler RxJS observables, and the transformations they can represent in a declarative way are very powerful. You can wire them up in a certain configuration and then they run themselves. So I see a lot of benefit for making it expandle. S has the S-Array library but the hoisting is super awkward since Signals are just functions etc. Every person who wants to make a new operator needs to do a lot of work. WIth this approach anyone can write Signal operators, and throw it up on Github. And anyone can import the ones they want to use and then just use it.
from solid.
While I am a very big proponent of functional programming patterns and think this is the correct way to develop operators out for Solid I think rendering is a special case and I've made specialized constructs now for loops and conditionals. In so I've removed the operators from the core. While I could see a separate package to support them where needed I think it might be completely unnecessary with the new API. With Proxies doing away with the need for specialized operators for Arrays and rendering being a special case I think this is probably something more for the implementor. I may revisit in the future but for now operators are gone.
from solid.
Related Issues (20)
- Batch top level effects to make them behave consistent with regular effects HOT 1
- SVG attribute stdDeviation changes to lowercase when used with a reactive variable HOT 5
- `createMutable` intensive testing HOT 1
- Updating parent component state causes child to lose state HOT 4
- ref ins rsbuild failed HOT 3
- Exports from ./dist do not include corresponding type declarations
- strange hydration mismatch HOT 3
- Typescript - Components created via JSX "forget"/erase their type HOT 3
- Custom elements using `is` not recognized as custom elements HOT 3
- onCleanup is called on the server and it breaks the astro app HOT 1
- [Bug?]: SuspenseList hydration error HOT 2
- computations created outside a `createRoot` or `render` will never be disposed HOT 3
- [Astro] `createResource` results get mixed up when rendering server only components with Suspense HOT 4
- Hydration Mismatch error HOT 6
- [Bug] Repeated call syntax in JSX breaks reactivity HOT 1
- [Astro] resource and signal rendering is mixed up on the client HOT 2
- Refs don't work correctly when using dynamic
- Refs don't work when optional on a component HOT 4
- Cannot use istanbul ignore comments for generated code HOT 2
- setting element reference in `setStore` modifies the values in the array HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid.