DEV Community

Discussion on: You probably don't need Redux: Use React Context + useReducer hook

 
artydev profile image
artydev • Edited

Think of streams as Excel cells and you will have a good starting point.
I have written a few lines as introduction here

streams

Thread Thread
 
artydev profile image
artydev • Edited

You absolutely don't need RxJS, as I said earlier you only need map and scan for Meiosis

Here is very simple stream implementaion with a map function :

function Stream (value) {
  let storedvalue = value
  let mappers = []
  function stream (newvalue) {
    if (arguments.length) {
      mappers.map(f => f(newvalue))
      storedvalue = newvalue
    }
    return storedvalue
  }
  stream.map = function (f) {
    mappers.push(f)
  }
  return stream
}

s = Stream()

document.addEventListener("mousemove", s)

s.map(t => divmouse.innerHTML = (`<h2>(${t.clientX}, ${t.clientY})</h2>`)) 

You can test it here :

StreamMap

Regards

Thread Thread
 
leob profile image
leob

Thanks, excellent, yes I get the idea ... I only mentioned RxJS because that's how I ever heard about streams and observables :-)

So can I put it like this: Streams provide a different approach (paradigm, if you will) to working with state in an "immutable" way?

Because that's basically what Redux and Context (and all of React, for that matter) tell us:

Do NOT modify state directly - return a new copy of your state, so treat it as 'immutable' ... streams do just that, but in a different (and probably easier or more powerful) way.

Thread Thread
 
artydev profile image
artydev • Edited

:-)

I am in favor of simplicity, If you are creating a project for your own needs, you really don't need heavy tools.

Use Meiosis with whatever view library you want or nothing eventually.

May I suggest you to use Mithril ?, simple, light and a very kind community :-)

Regards

Thread Thread
 
leob profile image
leob

I've heard about Mithril, but I also heard that Svelte is the greatest thing since sliced bread ... can you compare those two?

Thread Thread
 
artydev profile image
artydev • Edited

Much has been said on Svelte the "javascript compiler".
I can only agree with the speed and tiny apps it produces.
But for my needs I don't see what it brings more than Mithril

Mithril is only Javascript, with Svelte you have to learn a new syntax,
and you can't start without tooling, so integrate it into existing applications is not obvious

For example I needed to extends functionality to an Editor by adding a 'photo' button
with Mithril it was a piece of cake, It would not been that easier with Svelte.

JoditMithril

The more you use Mithril the more you know Javascript, I am not sure this is the case for all the well known frameworks

Thread Thread
 
leob profile image
leob

Right, yes I understand that they're different philosophies, more or less the opposite ...

Mithril is something you can drop into an existing page to enhance it, Svelte is more something you use to build a complete standalone app, it doesn't easily integrate, and it introduces its own tooling and syntax (a bit comparable with Vue with its template syntax, while React takes pride in sticking closer to standard JS, at least that's what it claims).

Totally different beasts really :-)

Thread Thread
 
artydev profile image
artydev • Edited

:-) you can also build complete apps with Mithril.

Among Mithril's users Nike.

Look carefully to this page :-)

Who use Mithril

Regards