GithubHelp home page GithubHelp logo

reversing order of operator? about solid HOT 3 CLOSED

solidjs avatar solidjs commented on May 5, 2024
reversing order of operator?

from solid.

Comments (3)

ryansolid avatar ryansolid commented on May 5, 2024

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.

ryansolid avatar ryansolid commented on May 5, 2024

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.

ryansolid avatar ryansolid commented on May 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.