nathancahill / split

Unopinionated utilities for resizeable split views
https://split.js.org/
MIT License
6.1k stars 448 forks source link

Multiple track registration constructor vs add api (split-grid) #781

Open njaldea opened 1 year ago

njaldea commented 1 year ago

Please refer to reproduction below: Reproduction

It has two versions (Constructor and Api) both are doing the same thing:

For Constructor, it works fine (but i guess i am doing something I should not be doing) For Api, only the last div for track works (3rd div for column. and 3rd div for row 1 and row 3)

Constructor works because it does not "cleanup" duplicates.

        this.options.columnGutters.forEach(gutterOptions => {
            this.columnGutters[gutterOptions.track] = createGutter(
                'column',
                this.options,
            )(gutterOptions)
        })

if gutterOptins.track has duplicates, it does not destroy the previous one, though i guess, based on code, that i should not do this (?)

For Api, it is a different story

    addColumnGutter(element, track) {
        if (this.columnGutters[track]) {
            this.columnGutters[track].destroy() // <-- this one
        }

        this.columnGutters[track] = createGutter(
            'column',
            this.options,
        )({
            element,
            track,
        })
    }

Is it intentional that there can only be one element per track? My intention is to add an orthogonal control (so that intersection can control both directions at the same time when resizing)

njaldea commented 1 year ago

I think either one of the following should happen.

  1. Support multiple element per track (i like this one but i don't know if it conflicts with the goals and design of the library)
  2. Constructor should just call addColumnGutter/addRowGutter so it will cleanup the duplicates automatically. Though maybe this restriction might be good to be added in the documentation so users (me) would be informed

Thank you!