Giter VIP home page Giter VIP logo

Comments (10)

Raynos avatar Raynos commented on May 28, 2024

sounds like your using a triple nested array as a 3d matrix.

I recommend that you do something like

render() {
  h('.foo', { 'data-click': event(events.handler, { pos: [i, j, k] }) }
}

And then do

function handler(state, data) {
  state.arr.get(toIndex(state.pos)).prop.set('foo')
}

from mercury.

Raynos avatar Raynos commented on May 28, 2024

An alternative solution is to use more components.

If you put events for a component at state.arr.get(i).get(j).events and you put that list at state.arr.get(i).get(j).list

Then in a component it's own "state" is going to be state.arr.get(i).get(j) and in the event handler you just use event(events.handler, { pos: k }) Then in the handler you just do state.list.get(k).prop.set('foo')

Basically by moving the events hash from the top level to some level inside the state you can effectively prefix everything in the state, rendering & event handlers by some index.

This is using a technique similar to lenses

from mercury.

Raynos avatar Raynos commented on May 28, 2024

@Swatinem I added https://github.com/Raynos/mercury/blob/master/docs/faq.md#how-do-i-avoid-deeply-nested-paths--structures to the FAQ to explain in more detail how to avoid this problem.

I hope this is a solution you can use

from mercury.

Swatinem avatar Swatinem commented on May 28, 2024

Yes, that looks really good so far.
But again, I have intermingled the data state and ui state.
When I have a listener on state.arr (or state.calendar in your example), I can’t simply JSON.stringify() and POST that to a server without removing all the events and ui-specific state i added through.
Same thing as I asked in #39

from mercury.

Raynos avatar Raynos commented on May 28, 2024

@Swatinem that is correct.

The state that you pass to mercury.app() is the ui state

If you want a seperate data state that you can JSON.stringify & POST you will have to model that explicitely and make the state you pass to mercury.app() be computed from it.

I'll create an example of this.

@Swatinem I actually think this is a seperate question from both #40 and #39

It's basically seperation of serializable state and actual application state

from mercury.

Raynos avatar Raynos commented on May 28, 2024

@Swatinem added a placeholder to the FAQ about this ( https://github.com/Raynos/mercury/blob/master/docs/faq.md )

from mercury.

Swatinem avatar Swatinem commented on May 28, 2024

Thanks for taking care of this!

So yes, it is all somehow connected.
And in my component I want both.
Application state (might be local to a component) that toggles a selected tab, or the open state of a dropdown, with event handlers that work on that state.

And serializable state that actually holds my data. And events that work on that particular state.

Both should of course be convenient to use. :-)

from mercury.

Swatinem avatar Swatinem commented on May 28, 2024

Another question: Does observ support references?
With those you can have your serializable state in a different subtree but have references to the items from your application state tree.

from mercury.

Raynos avatar Raynos commented on May 28, 2024

@Swatinem what do you mean references ? you can embed an observ in multiple locations.

from mercury.

Swatinem avatar Swatinem commented on May 28, 2024

yes thats what i mean. Like my https://github.com/Swatinem/cow

from mercury.

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.