Feed Aggregator Page 662
Rendered on Fri, 16 Oct 2020 07:03:51 GMT
Rendered on Fri, 16 Oct 2020 07:03:51 GMT
via Elm - Latest posts by @csuvikv Viktor Csuvik on Fri, 16 Oct 2020 06:28:08 GMT
Thanks for your suggestion, I already tried that. The problem is, that in the github repository the code is written in elm 0.19 so it’s not compatible with my version (there is no elm-package.json, only elm.json). Btw if I could find an older version of it I think it should work
via Elm - Latest posts by @RickBradford Rick Bradford on Fri, 16 Oct 2020 03:59:09 GMT
To go back to my city/country situation, let us say I have chosen the first main category ‘Italy’ and the third sub-category ‘Venice’.
If I now change the main category from Italy to Greece, this repopulates the sub-category with the cities of Greece, and the select item still shows the third sub-category item, now perhaps ‘Heraklion’, but there is no way to inform the view function to change the information,shown for this item, unless I have the index and can pass it to the view function.
Your initial suggestion was that changing the main category could result in a ‘No City Selected’ view, but if possible I want to do better than that and show the relevant item.
via Elm - Latest posts by @Sebastian Sebastian on Fri, 16 Oct 2020 03:51:58 GMT
If you want to get the index from the select you could render your options using List.indexedMap
. Then pass the index to the message somehow.
But also, why do you want the index? Usually there is better solution in Elm that doesn’t involve using indexes.
via Elm - Latest posts by @system system on Fri, 16 Oct 2020 03:51:18 GMT
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
via Elm - Latest posts by @RickBradford Rick Bradford on Fri, 16 Oct 2020 03:48:01 GMT
Yes, that should work, thanks.
It’s getting the index not from the ‘select’ item itself, but from the List used to populate the ‘select’ item, but that shouldn’t be an issue as I’m not deleting or adding to the items.
via Elm - Latest posts by @Sebastian Sebastian on Fri, 16 Oct 2020 03:30:31 GMT
https://package.elm-lang.org/packages/elm-community/list-extra has elemIndex
that should work for this
via Elm - Latest posts by @system system on Fri, 16 Oct 2020 02:04:23 GMT
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
via Elm - Latest posts by @RickBradford Rick Bradford on Fri, 16 Oct 2020 01:41:20 GMT
OK, that’s a good interim solution, thanks.
In Elm, is there any way of retrieving the current index of a ‘select’ item? My feeling, based on limited research, is ‘no’.
via Elm - Latest posts by @Sebastian Sebastian on Fri, 16 Oct 2020 00:49:08 GMT
In the type we use ParentChildSelection
the index of the sub-category is not carried over when you change the country. This becomes ParentSelected Greece
. So there is no data about the selected city anymore. The view can show No city selected
as you suggest.
So the country dropdown produces a message like ChangeSelection (ParentSelected Greece)
and the city dropdown produces ChangeSelection (ChildSelected Greece Athens)
via Elm - Latest posts by @RickBradford Rick Bradford on Fri, 16 Oct 2020 00:38:53 GMT
That’s the core of the problem. The ‘index’ of the sub-category is carried over when the main category is changed, so the ‘view’ function does not know what to display.
It could display a generic ‘No city selected’ view, I suppose, but that still wouldn’t really be in sync.
via Elm - Latest posts by @Sebastian Sebastian on Fri, 16 Oct 2020 00:36:59 GMT
For this we use a type ParentChildSelection
type ParentChildSelection
= NoSelection
| ParentSelected String
| ChildSelected String String
If you select a new country, this will become ParentSelected Greece
. In that case the view will need to decide what to show for city.
After selecting a city this becomes ChildSelected Greece Athens
. We keep the id of the parent here for easy lookup.
via Elm - Latest posts by @RickBradford Rick Bradford on Fri, 16 Oct 2020 00:31:32 GMT
In my Elm app, I have two ‘select’ elements, ie dropdowns. The first is the main category, the second a list of sub-categories dependent on the content of the main category.
For example, if the main category shows a list of countries, then the sub-category contains a list of cities within that country. The ‘view’ function is then instructed to show information relevant to that city.
Whenever I change the main category, the contents of the sub-category change to show the relevant items.
But what I cannot do is to access the index of the sub-category. If I have selected main category ‘Italy’ and sub-category ‘Milan’, when I change the main category from ‘Italy’ to ‘Greece’, I want to reset (or retrieve) the current index of the sub-category, so that I know what information to display in the ‘view’ function.
If I cannot do this, then what appears as the sub-category item is out of sync with the information displayed in the ‘view’ function.
Is there some way to do this?
via Planet Lisp by on Thu, 15 Oct 2020 22:18:00 GMT
Lisp programmers are of the opinion that [] and {} are just () with delusions of grandeur.via Elm - Latest posts by @rupert Rupert Smith on Thu, 15 Oct 2020 22:35:43 GMT
Thinking about it, do I even need the big divs before and after the viewport? I was going to use “position: absolute” on each line div anyway. So if I just position the lines correctly within the overall container div, and then scroll that? I’ll give it a go anyway.
via Elm - Latest posts by @rupert Rupert Smith on Thu, 15 Oct 2020 19:12:15 GMT
That sounds like a good idea and has the advantage that you just use overflow: scroll
on the containing div, no need for putting scroll bars in separate divs. Thanks.
via Elm - Latest posts by @hans-helmut Hans-Helmut on Thu, 15 Oct 2020 18:35:59 GMT
I had done a similar thing, scrolling a list with 100000 entries. It works, as long the displayed lines or entries have the same height. I used an idea, I found somewhere on github, implemented in jquery, but I can not find the original source anymore.
It works like that:
Each text-line is a div. Calculate, how may pixel this div needs vertical, e.g. by drawing a test-div.
Create a scrollable div, the scene (https://package.elm-lang.org/packages/elm/browser/latest/Browser.Dom). In this scene display the divs containing lines.
Now the optimization:
Merge all divs with lines before the viewport to one big div, without any content.
Similar merge for all divs after the viewport.
So only the viewable divs with lines are rendered.
For better user-experience with small scrolls add some divs with content before and after the viewport (and decrease the big divs properly)
via Elm - Latest posts by @rupert Rupert Smith on Thu, 15 Oct 2020 17:09:23 GMT
I’m currently doing a spike on setting up custom scrolling logic in Elm.
The idea is that if you have a large file to display, perhaps a log or a large file in an editor, rendering the full view
for it each time, can be slow. The default way of using overflow: scroll
on the div
works, but is not optimal. Instead scroll bars are set up in separate div
s to the one showing the content, their scroll events are hooked up, and custom logic will take a slice of the content and render a smaller view just for what is visible.
Has anyone done this before?
I’m taking some inspiration from CodeMirror - handy at least to be able to see how this is done in Javascript, and what the CSS used there is.
The current WIP is here:
demo: https://mystifying-gates-6761c1.netlify.app/
code: https://github.com/rupertlssmith/elm-scroll-spike/blob/main/src/elm/Main.elm
Going to be looking at:
via Elm - Latest posts by @system system on Thu, 15 Oct 2020 16:10:50 GMT
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
via Elm - Latest posts by @system system on Thu, 15 Oct 2020 15:17:52 GMT
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
via Elm - Latest posts by @evancz Evan on Thu, 15 Oct 2020 15:13:53 GMT
I do not recall exactly how the 0.18 download process works, but here’s what I would try.
If I remember correctly, the packages are all downloaded into folders in your project’s elm-stuff/
directory like this:
elm-stuff/0.18.0/Skinney/murmur3/2.0.6/
If I recall correctly, it downloads the package when it does not see a src/
directory on that path, so if you download the code yourself into that location, I think 0.18.0 will assume that it downloaded it in the past for some reason.
I’m not 100% certain that I am remembering all the details, but I think this is roughly what I would look into first!