Feed Aggregator Page 648
Rendered on Fri, 18 Sep 2020 11:33:33 GMT
Rendered on Fri, 18 Sep 2020 11:33:33 GMT
via Elm - Latest posts by @system system on Fri, 18 Sep 2020 06:35:15 GMT
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
via Elm - Latest posts by @pdamoc Peter Damoc on Fri, 18 Sep 2020 03:30:39 GMT
You can pass arguments (like the current time if you got it as a flag) to the init
from another module.
Can you provide more information about this? init
is just a regular function, it is not obvious why it would need a view
. In any case, an empty view is usually text ""
.
via Elm - Latest posts by @evancz Evan on Fri, 18 Sep 2020 00:05:55 GMT
It appears that Robin has republished the packages under the new name, so it should now be possible to swap Skinney/murmur3
to robinheghan/murmur3
in your elm.json
as well.
via Elm - Latest posts by @Yannick971 Yannick on Fri, 18 Sep 2020 00:02:39 GMT
Newbie question… There is a value from the model of Main.elm
that I would need to access in a module, the module being itself imported in Main…hence the circular import…
is there a way around this, or I just have to rethink my design?
I believe it’s the latter…
At first, I wanted to have this value computed in the module, not in Main
, but I needed it to be initialized on the app startup. (This value is computed from the current time, to give you context).
Is there a way to initialize this task in a module, on app startup? I guess so but I couldnt figure it out. Can I just use init
without view
? Is there something like view.None
to tell Elm there is no view here ?
So I ended up doing this in the Main init
and it created this circular import bug because I was importing the value from Main into the module…
via Elm - Latest posts by @francescortiz Francesc Ortiz on Thu, 17 Sep 2020 22:59:48 GMT
What about this:
It does the effect, but the bounding box box remains. You have remove it afterwards, but you would remove the modal anyway.
via Elm - Latest posts by @iwtilma on Thu, 17 Sep 2020 21:04:39 GMT
Thanks for this solution too. For now I don’t need the order, but I will keep this in mind for future development.
via Elm - Latest posts by @iwtilma on Thu, 17 Sep 2020 21:03:43 GMT
Thank you very much. It works like a charm!
Still learning a lot.
via Planet Lisp by on Thu, 17 Sep 2020 19:47:58 GMT
This is an interesting templating library. The most interesting features are:
Here is how template functions can be reused:
POFTHEDAY> (cl-emb:register-emb "user-list"
"
<ul>
<% @loop users %>
<li><% @call user %></li>
<% @endloop %>
</ul>
")
POFTHEDAY> (cl-emb:register-emb "user"
"<a href=\"/users/<% @var nickname %>\"><% @var name %></a>")
POFTHEDAY> (cl-emb:execute-emb "user-list"
:env '(:users
((:nickname "bob"
:name "Bob Hopkins")
(:nickname "alice"
:name "Alice Cooker"))))
"
<ul>
<li><a href=\"/users/bob\">Bob Hopkins</a></li>
<li><a href=\"/users/alice\">Alice Cooker</a></li>
</ul>
"
Let's see which code was generated for "user-list". To make this work, we'll need to set *debug*
variable and recompile the template:
POFTHEDAY> (cl-emb:pprint-emb-function "user-list")
(LAMBDA
(
&KEY CL-EMB-INTERN::ENV CL-EMB-INTERN::GENERATOR-MAKER
CL-EMB-INTERN::NAME)
(DECLARE (IGNORABLE CL-EMB-INTERN::ENV CL-EMB-INTERN::GENERATOR-MAKER))
(LET ((CL-EMB-INTERN::TOPENV CL-EMB-INTERN::ENV)
(CL-EMB-INTERN::TEMPLATE-PATH-DEFAULT
(IF (TYPEP CL-EMB-INTERN::NAME 'PATHNAME)
CL-EMB-INTERN::NAME
*DEFAULT-PATHNAME-DEFAULTS*)))
(DECLARE
(IGNORABLE CL-EMB-INTERN::TOPENV CL-EMB-INTERN::TEMPLATE-PATH-DEFAULT))
(WITH-OUTPUT-TO-STRING (*STANDARD-OUTPUT*)
(PROGN
(WRITE-STRING "
<ul>
")
(DOLIST
(CL-EMB-INTERN::ENV
(CL-EMB::AUTOFUNCALL (CL-EMB::GETF-EMB "users")))
(WRITE-STRING "
<li>")
(FORMAT T "~A"
(LET ((CL-EMB:*ESCAPE-TYPE* CL-EMB:*ESCAPE-TYPE*))
(CL-EMB:EXECUTE-EMB "user" :ENV CL-EMB-INTERN::ENV
:GENERATOR-MAKER
CL-EMB-INTERN::GENERATOR-MAKER)))
(WRITE-STRING "</li>
"))
(WRITE-STRING "
</ul>
")))))
As you can see, cl-emb
generates a straight forward Lisp code.
Now let's check how fast cl-emb
is and compare it to HTML template engines reviewed in previous days:
POFTHEDAY> (cl-emb:register-emb "render"
"
<title><% @var title %></title>
<ul>
<% @loop items %><li><% @var value %></li><% @endloop %>
</ul>
")
POFTHEDAY> (time
(loop repeat 1000000
do (cl-emb:execute-emb "render"
:env '(:title "Foo Bar"
:items ((:value "One")
(:value "Two")
(:value "Three"))))))
Evaluation took:
1.436 seconds of real time
1.441475 seconds of total run time (1.421158 user, 0.020317 system)
[ Run times consist of 0.104 seconds GC time, and 1.338 seconds non-GC time. ]
100.35% CPU
3,172,183,256 processor cycles
767,974,304 bytes consed
That is pretty fast. Slightly slower than Spinneret
but faster than Zenekindarl
.
To learn more about cl-emb's features, read it's docs!
via Elm - Latest posts by @evancz Evan on Thu, 17 Sep 2020 19:19:45 GMT
It looks like there’s some discussion of work arounds on Slack as well. I’m copying the content of this message from turbo_mack (with some edits for weird formatting issues)
Some of you who depend on great work of @Robin might experience some issues due to package.elm not liking the fact he changed his name on Github. While this issue is being resolved you can use this workaround to make CircleCI pass:
# within home $ cd $HOME # create tarball of ~/.elm $ tar -czvf elm-cache.tar.gz .elm # copy tarball to project $ cp elm-cache.tar.gz my-project/directory # commit tarball
in our case we use circle-ci but it should be easy to port
- run: name: patch cache command: | tar -xzf elm-cache.tar.gz mv -f .elm $HOME/.elm
The important parts are these two commands:
tar -czvf elm-cache.tar.gz ~/.elm # create tarball
tar -xzf elm-cache.tar.gz # unpack taraball
Any CI system could probably make a work around with some form of these commands.
via Elm - Latest posts by @evancz Evan on Thu, 17 Sep 2020 19:00:13 GMT
I believe the root issue is a user name change on GitHub, from Skinney
to robinheghan
, which ends up changing the hashes for releases.
I sent some chats to @robin.heggelund of possible paths and how I can help if needed, but in the meantime, you can get your CI unstuck by placing the following directory on it:
~/.elm/0.19.1/packages/Skinney/murmur3/2.0.8
You should have this on your local development system.
Zip it up, and add a temporary line before you run any Elm stuff to place this directory on the CI machine.
CI Note: I very highly highly highly encourage people with CI to cache your ~/.elm
directory from build to build. This will make you immune to DNS issues, GitHub downtime, or things like this scenario! That directory just contains (1) static files that have been downloaded and (2) the build artifacts they produce deterministically. The one thing that can go wrong is acquiring the files over HTTP!
Hashing Note: The current design for hashing was chosen under the assumption that hashes of GitHub zip files would be based strictly on the content of the files, but it appears that incidental information about how GitHub hosts things also makes its way into these hashes. It is stable in general, but certain things can knock it out of whack. So I’d like to switch how hashes are generated to an approach that takes longer, but cannot be tripped up by these details. This is an infrastructure that’s much larger than it sounds, but it is highest priority for any package work.
via Elm - Latest posts by @eike Eike Schulte on Thu, 17 Sep 2020 18:37:56 GMT
The other solution works (I think) but it does simply ignore the information encoded in the numbers and assumes that the fields are always decoded in the right order. This will probably be the case but I think strictly speaking the fields in an object are unordered (so the sender or JavaScript or Elm would be free to present them in a different order). In particular, you should check that keys from “10” on are in the right order because they might also come in lexicographic order where “10” is smaller than “2”.
If that is a problem, I would do something like this and use it to write the “boxes” and “items” decoders
decodeStrangeList : Decoder a -> Decoder (List a)
decodeStrangeList sub =
Decode.dict sub
|> Decode.andThen
(\stringDict ->
stringDict
|> Dict.foldl
(\string value mIntDict ->
case (String.toInt string, mIntDict) of
(Just int, Just intDict) ->
Just (Dict.insert int value intDict)
_ ->
Nothing
)
Just Dict.empty
|> Maybe.map (Dict.values >> Decode.succeed)
|> Maybe.withDefault (Decode.fail "One of the keys was not an integer")
)
(I must admit that I did not test this.) This solution will return the elements in the right order. It does not check that every key exists, so if the indices are important, an even more complicated solution would be necessary.
via Elm - Latest posts by @hexedhash Giorgio on Thu, 17 Sep 2020 18:16:26 GMT
I am seeing the following stack trace in my ci/cd pipeline when installing elm packages.
2:08:33 PM: Starting downloads...
2:08:33 PM: ✗ Skinney/murmur3 2.0.8
2:08:33 PM: ● elm/random 1.0.0
2:08:33 PM: ● elm/regex 1.0.0
2:08:33 PM: ● elm/time 1.0.0
2:08:33 PM: ● elm/html 1.0.0
2:08:33 PM: ● elm/parser 1.1.0
2:08:33 PM: ● truqu/elm-base64 2.0.4
2:08:33 PM: ● elm/browser 1.0.2
2:08:33 PM: ● elm/virtual-dom 1.0.2
2:08:33 PM: ● elm/bytes 1.0.8
2:08:33 PM: ● elm/url 1.0.0
2:08:33 PM: ● rtfeldman/elm-hex 1.0.0
2:08:33 PM: ● elm/svg 1.0.1
2:08:33 PM: ● elm/http 2.0.0
2:08:33 PM: ● elm/json 1.1.3
2:08:33 PM: ● elm/core 1.0.5
2:08:33 PM: ● elm/file 1.0.5
2:08:33 PM: ● elm-explorations/test 1.2.2
2:08:33 PM: ● pablohirafuji/elm-syntax-highlight 3.3.0
2:08:33 PM: ● rtfeldman/elm-css 16.0.1
2:08:33 PM: Verifying dependencies (19/20)
2:08:33 PM: Verifying dependencies (20/20)-- CORRUPT PACKAGE DATA --------------------------------------------------------
2:08:33 PM: I downloaded the source code for Skinney/murmur3 2.0.8 from:
2:08:34 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
2:08:33 PM: https://github.com/Skinney/murmur3/zipball/2.0.8/
2:08:33 PM: But it looks like the hash of the archive has changed since publication:
2:08:33 PM: Expected: 81a0bada79740ae806df04b1bb14a7d64f763ac5
2:08:33 PM: Actual: 931398ec656078e26b2e29520cd283ffe6e8e441
2:08:33 PM: This usually means that the package author moved the version tag, so report it
2:08:33 PM: to them and see if that is the issue. Folks on Elm slack can probably help as
2:08:33 PM: well.
Is anyone else running into this?
via Elm - Latest posts by @stephenreddek Stephen Reddekopp on Thu, 17 Sep 2020 17:25:45 GMT
Oh I’m sorry! You’re absolutely right. I missed the List.map
inside the Decoder.map
. I’ll update that in my answer. It’ll just be Json.Decode.keyValuePairs (Json.Decode.String) |> Json.Decode.map (List.map (\(key, value) -> value))
via Elm - Latest posts by @iwtilma on Thu, 17 Sep 2020 17:21:06 GMT
Thank you, stephenreddek, for your clear answer. I try to make it work using Json.Decode.keyValuePairs, but that raises a question: are you sure about the pipeline with Json.Decode.map ((key, value) -> value)? Elm doesn’t accept it:
The argument is:
Decoder (List ( String, String ))
But (|>) is piping it to a function that expects:
Decoder ( a, value )
I could keep the list of key-value pairs and map them into values only later using List.map. What do you suggest?
via Elm - Latest posts by @hexedhash Giorgio on Thu, 17 Sep 2020 16:58:02 GMT
Why does that seem hacky to you?
Suppose there are 3 alerts on the page, all of which have different heights. For each alert I need to generate a unique id
value to call Browser.Dom.getElement
and get the correct value back. Generating unique ids would likely impact the user-facing API of the alerts. And I want to make sure that the alert API is intuitive and simple.
via Elm - Latest posts by @eimfach Robin G. on Thu, 17 Sep 2020 16:54:00 GMT
Why does that seem hacky to you? The dynamic height needs a dynamic solution … If the css transition does require a fixed height, this seems straightforward…
via Elm - Latest posts by @stephenreddek Stephen Reddekopp on Thu, 17 Sep 2020 16:42:29 GMT
There are a couple different ways to model this data structure. When the keys of an object are dynamic, often you’ll want to model this in Elm with a Dict
. However, it looks like they’re really just incrementing with each value so many these are better handled as a List
. That’s up to you!
If you go down the Dict
path, perhaps your elm model might look like { boxes : Dict String (Dict String String) }
(You could also decide to convert the string keys to integers if you wanted). To go down this route, you would use the dict decoder. The dict decoder takes in a decoder for the value and then decodes the keys as strings. The inner items
decoder would look something like this: Json.Decode.dict Json.Decode.string
and would have the signature: Decoder (Dict String String)
. You would nest this decoder inside another Dict decoder to make your final decoder.
If you go down the List
path, your model could look something like { boxes : List (List String) }
. To Decode that, you have to do a couple steps. You could use the key-value pairs decoder to decode the object into a list of the keys and values. You could take that result and transform it into just your items by only taking the values. That decoder works like the dict
decoder in that it takes in a decoder for the values and keeps the keys a String
. You can decode the items part like this: Json.Decode.keyValuePairs (Json.Decode.String) |> Json.Decode.map (\(key, value) -> value)
. That would decode your object of items into a list of the contained items. This would have the signature Decoder (List String)
.
I hope that answers your question and points you in the right direction!
via Elm - Latest posts by @hexedhash Giorgio on Thu, 17 Sep 2020 16:36:45 GMT
cc @Lucas_Payr
… (had to add extra chars to post the comment haha)
via Elm - Latest posts by @hexedhash Giorgio on Thu, 17 Sep 2020 16:30:19 GMT
Hey friends,
I’m the author of elm-antd and am currently trying to implement closeable alerts (see here for the reference design).
I have a proof-of-concept implementation that I have ported over to elm using elm-css.
Just like in the codepen above, I dymaically add a is_closing
attribute of true
to the element when it’s clicked in order to change various css properties (height, opacity and overflow).
There is one issue though. My proof-of-concept implementation requires an explicit height value so that the css transition can go from some known height down to 0 smoothly.
Without an explicit height, the animation does not work, and the element’s CSS properties change immediately without a transition.
An easy fix would be to add height (px whateverHere)
in my elm code, but I don’t want to hard-code a height on my actual elm implementation because that would mean that the alert’s height doesn’t automatically adjust to the contents of the alert component.
What I’m considering doing is querying the DOM using Browser.Dom.getElement
in order to retrieve the height of the rendered element … but this just seems hacky in my opinion.
I am also trying to not use 3rd party packages either as most of them impose a particular way of doing things that would cascade down to users of elm-antd.
Any suggestions on how to address this? Maybe there’s an entirely different way of doing this animation that is a lot simpler?
via Elm - Latest posts by @iwtilma on Thu, 17 Sep 2020 16:18:33 GMT
I want to decode a JSON object that looks like this:
{
"boxes" : {
"1" : {
"items" : {
"1" : "pencil",
"2" : "ball"
},
},
"2" : {
"items" : {
"1" : "teapot",
"2" : "spoon",
"3" : "towel"
}
}
}
}
I have no control over the JSON format. I get it from an external server.
My problem while decoding is that I don’t know how many boxes the JSON contains nor how many items each box contains.
I would like to decode it into a List of boxes that contains a List of items. How should I approach this?
Thanks in advance!