workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
elmlang
general
The browser doesn't allow even JS to know the difference between a CORS problem and a network failure
2019-03-25T18:38:48.718600
Earlean
elmlang
general
With CORS, it's up to the server to respond with headers that tell the browser it can allow the request. Inspect the headers of the response to see what the server's requirements are for the request.
2019-03-25T18:43:57.718800
Earlean
elmlang
general
there are none in browser...
2019-03-25T19:18:11.719100
Floy
elmlang
general
but there's a bunch of when I execute it via `httpie`
2019-03-25T19:18:24.719300
Floy
elmlang
general
setting cookies etc.
2019-03-25T19:18:50.719500
Floy
elmlang
general
an alternative is to talk with the API
2019-03-25T19:20:26.719700
Floy
elmlang
general
nvm...I though that might be easy stuff with something obvious missing, but apparently it's not :confused:
2019-03-25T19:22:39.720000
Floy
elmlang
general
anyway, thx for help
2019-03-25T19:22:46.720200
Floy
elmlang
general
it's easy stuff as long as their server supports CORS
2019-03-25T19:23:15.720400
Earlean
elmlang
general
if not, then it's impossible stuff. But it would be impossible with JS too.
2019-03-25T19:23:37.720600
Earlean
elmlang
general
if you have JS that talks to wakatime then inspect the requests and response it gets
2019-03-25T19:24:33.720800
Earlean
elmlang
general
You can also set up a cors proxy in a trusted server of yours, and query that.
2019-03-25T20:30:13.722200
Bebe
elmlang
general
Don’t use third party cors servers with sensitive requests
2019-03-25T20:30:45.723000
Bebe
elmlang
general
BTW <@Todd> there's a <#C7075S0GY|compile-time> that you might be interested in.
2019-03-25T21:15:43.723200
Carlota
elmlang
general
Thanks a lot for the assistance, i wasn't online to continue, i m now going to try it
2019-03-26T00:11:21.723600
Leopoldo
elmlang
general
Solved it. The problem was that i made a mistake creating the URL. I got a CORS error instead of a 404. A bit confusing, but there might be good reasons for doing it that way I guess.
2019-03-26T02:49:25.724400
Luba
elmlang
general
why the `(Json.succeed SyncViewport)` ?
2019-03-26T03:08:30.724600
Leopoldo
elmlang
general
hows does everyone manage not re-initing nested components on the OnChangeUrl?
2019-03-26T03:30:15.725900
Euna
elmlang
general
I feel as though I am missing some key philosophy
2019-03-26T03:30:31.726400
Euna
elmlang
general
like if you change url from /profile/something to -&gt; /profile/anotherthing how do you maintain consistent state
2019-03-26T03:40:14.727500
Euna
elmlang
general
I havent done routing in a while, but when that `OnChangeUrl` `Msg` comes in, you should be able to handle the `Route` like this: ``` Route.Profile id -&gt; case model.page of Page.profile subModel -&gt; if subModel.id == id then model -- Dont do anything ```
2019-03-26T03:45:15.729100
Ashton
elmlang
general
This is an extreme case where you literally dont want to do anything at all, and no state is changed, but in other cases you can do different things.
2019-03-26T03:45:48.729700
Ashton
elmlang
general
wow, thank you so much for the reply, these are some very impressive numbers
2019-03-26T04:53:05.730400
Todd
elmlang
general
^.^
2019-03-26T05:42:11.730700
Denae
elmlang
general
Hi. I am working on Kite. Could you describe to me what you do with Kite? I kind of lack user data. :slightly_smiling_face:
2019-03-26T05:52:01.730900
Reuben
elmlang
general
if you have a particular need (from Kite), I can increase its priority in the roadmap: <https://github.com/erkal/kite/projects/1>
2019-03-26T05:54:20.731100
Reuben
elmlang
general
or maybe add it, if it is not already there
2019-03-26T05:54:57.731300
Reuben
elmlang
general
Hi all, has anyone done some design on mapping Parent -&gt; Children?
2019-03-26T06:25:35.732000
Zachary
elmlang
general
you need a decoder for a message and since I don’t want to do anything with the event, the simplest way to express the fact that I want `SyncViewport` message to be generated on that event is to just `Json.succeed SyncViewport`
2019-03-26T06:25:36.732100
Maida
elmlang
general
I'm currently using a `Dict Id Child.Model` to track model changes, is there something more abstract out there?
2019-03-26T06:26:18.733100
Zachary
elmlang
general
I later thought about the proposed solution and realized that it is broken.
2019-03-26T06:26:57.733500
Maida
elmlang
general
It works on ellie but i also noticed it only works on mousewheel
2019-03-26T06:28:03.734700
Leopoldo
elmlang
general
Provisions have to be made for arrows and scrollbars dragging
2019-03-26T06:28:28.735300
Leopoldo
elmlang
general
it really depends on your specific case. why `Dict Id Child.Model` doesn't fit your needs?
2019-03-26T06:28:36.735600
Lilli
elmlang
general
I m yet to incorporate into my existing code and see
2019-03-26T06:28:51.735700
Leopoldo
elmlang
general
it's quite some massaging to get it in
2019-03-26T06:31:05.736100
Zachary
elmlang
general
but it does the job :slightly_smiling_face:
2019-03-26T06:31:11.736300
Zachary
elmlang
general
questions that arise in my head after reading such a generic question: 1) mapping parent -&gt; children. Recursive tuples? json? nested maps/dicts? List of (id, record model, nullable parent id)? 2) what is your model made of? is each element unique? 3) tracking changes... maybe create a distinct model that acts as a index? can your model be hashed? 4) are performances a deciding factor? I don't want to appear polemic, but it feels like someone asked me how to carry "things" from a city to an other. If it's small enough, even a pigeon might do it :stuck_out_tongue:
2019-03-26T06:42:07.745200
Lilli
elmlang
general
TCP/IP over pidgeon?
2019-03-26T06:44:32.745500
Niesha
elmlang
general
<https://ellie-app.com/55HbSQ9mD6Na1>
2019-03-26T06:45:57.745600
Maida
elmlang
general
this should work OK
2019-03-26T06:46:02.745800
Maida
elmlang
general
I have moved the handling of the scroll in JS.
2019-03-26T06:46:33.746000
Maida
elmlang
general
if there is no kind of electric power, it might be the only choice :smile:
2019-03-26T06:48:49.746800
Lilli
elmlang
general
it's all about context
2019-03-26T06:49:06.747000
Lilli
elmlang
general
I have also created a discourse topic about this: <https://discourse.elm-lang.org/t/is-it-possible-to-handle-scroll-events-in-elm-without-the-use-of-ports/3396>
2019-03-26T06:59:40.747200
Maida
elmlang
general
Regarding Parsers: How to chomp until different character than last one?
2019-03-26T07:09:53.748500
Miguelina
elmlang
general
Question regarding generic record types and JSON decoding: can I?
2019-03-26T07:32:33.749200
Gertrude
elmlang
general
This is not as easy as it sounds, this should work: ``` module Chomp exposing (chompWhileUnique) import Parser exposing (..) chompWhileUnique : Parser () chompWhileUnique = loop Nothing chompWhileUniqueLoop chompWhileUniqueLoop : Maybe Char -&gt; Parser (Step (Maybe Char) ()) chompWhileUniqueLoop maybeChar = oneOf [ case maybeChar of Just char -&gt; getChompedString (chompIf (\c -&gt; char /= c)) |&gt; andThen chompWhileUniqueNextChar Nothing -&gt; getChompedString (chompIf (\c -&gt; True)) |&gt; andThen chompWhileUniqueNextChar , succeed (Done ()) ] chompWhileUniqueNextChar : String -&gt; Parser (Step (Maybe Char) ()) chompWhileUniqueNextChar str = case String.uncons str of Nothing -&gt; succeed (Done ()) Just ( c, _ ) -&gt; succeed (Loop (Just c)) ``` For example in `elm repl`: ``` &gt; run (getChompedString chompWhileUnique) "" Ok "" : Result (List DeadEnd) String &gt; run (getChompedString chompWhileUnique) "abcefg" Ok "abcefg" : Result (List DeadEnd) String &gt; run (getChompedString chompWhileUnique) "abccefg" Ok "abc" : Result (List DeadEnd) String ```
2019-03-26T07:35:21.750700
Velia
elmlang
general
ie I have a type like this: ``` type Project task = Project { id : Identifier , name : String , tasks : List task , closed : Bool } ``` Can I write a decoder in a generic way to handle `task` as one of several possible options? I've also tried instead creating a `Task` enum with all the types of task records that can be in there, but this seems to fail
2019-03-26T07:38:34.752100
Gertrude
elmlang
general
<@Gertrude> it's possible to write fully generic JSON decoder, have a look at : <https://package.elm-lang.org/packages/Microsoft/elm-json-tree-view/latest/>
2019-03-26T07:38:35.752200
Nana
elmlang
general
ah nvm
2019-03-26T07:39:16.752400
Nana
elmlang
general
Thx... this will take a while to absorb...
2019-03-26T07:39:42.753000
Miguelina
elmlang
general
<@Gertrude> Elm cannot generically derive decoders, no. However, you can ask it to try a few different decoders.
2019-03-26T07:39:50.753400
Niesha
elmlang
general
you could write `projectDecoder : Decoder a -&gt; Decoder (Project a)` just like `Decode.list`etc. work
2019-03-26T07:40:37.754300
Nana
elmlang
general
~~Hmm. I'm wondering if the issue is how to pass the right constructor to Decode.succeed. I guess enum record types don't create the same kind of constructor as a type alias~~ (wrong avenue)
2019-03-26T07:42:01.755100
Gertrude
elmlang
general
Ms doing elm dev??
2019-03-26T07:42:41.755500
Danika
elmlang
general
Well the use of `loop` makes it look more complicated than it is, but this avoids stack issues. It would look simpler by using a recursive parser.
2019-03-26T07:42:55.755600
Velia
elmlang
general
<@Danika> yup it's <@Carl> at MS
2019-03-26T07:43:44.756300
Nana
elmlang
general
you don't have to use a constructor if it doesn't fit. you can write your own function there that takes the parameters and composes a value of the right type
2019-03-26T07:44:36.757300
Sharon
elmlang
general
So I have my `Project` decoder defined like this: ``` projectDecoder : Decoder (Project task) projectDecoder = Decode.succeed mkProject |&gt; required "id" int |&gt; required "name" string |&gt; required "tasks" (Decode.oneOf [list reportableTaskDecoder, list markableTaskDecoder]) |&gt; required "closed" bool ``` And it complains about that `oneOf`, because the result is a mismatched list
2019-03-26T07:45:37.758300
Gertrude
elmlang
general
No, no... loop is totally fine! I just used it for building a list. It's just that I'm very new (2h) to parsers.
2019-03-26T07:47:15.758600
Miguelina
elmlang
general
Ok, anyway here is the recursive version without tail-call elimination: ``` chompWhileUnique : Parser () chompWhileUnique = chompWhileUniqueHelp Nothing chompWhileUniqueHelp : Maybe Char -&gt; Parser () chompWhileUniqueHelp maybeChar = oneOf [ case maybeChar of Just char -&gt; getChompedString (chompIf (\c -&gt; char /= c)) |&gt; andThen chompWhileUniqueNextChar Nothing -&gt; getChompedString (chompIf (\c -&gt; True)) |&gt; andThen chompWhileUniqueNextChar , succeed () ] chompWhileUniqueNextChar : String -&gt; Parser () chompWhileUniqueNextChar str = case String.uncons str of Nothing -&gt; succeed () Just ( c, _ ) -&gt; chompWhileUniqueHelp (Just c) ```
2019-03-26T07:49:30.758800
Velia
elmlang
general
`reportableTaskDecoder` and `markableTaskDecoder` both have their own task-type instead of the generic `task` ?
2019-03-26T07:51:16.760500
Sharon
elmlang
general
Yes. They're both record types, though similar, and the API is guaranteed to only ever have same type lists (ie. all projects have a list of only markable, or only reportable tasks)
2019-03-26T07:52:39.761300
Gertrude
elmlang
general
Thx!!
2019-03-26T07:53:27.762200
Miguelina
elmlang
general
I can express this potentially with an enum as well, but this gets cumbersome because I need to write constructor functions for each, which is a lot of code for only two record types possible, and also wrong, because a `type Task = Reportable | Markable` or similar enum would allow mixed type lists of tasks
2019-03-26T07:54:13.763100
Gertrude
elmlang
general
Well your function is trying to implement both `Decoder (Project ReportableTask)` and `Decoder (Project MarkableTask)` at once, but you can't do that because they are different types. I think the easiest is to just make 2 different functions. Then maybe see if you can extract common logic afterwards
2019-03-26T07:56:12.763500
Sharon
elmlang
general
<@Gertrude> ``` projectDecoder : Decoder task -&gt; Decoder (Project task) projectDecoder taskDecoder = Decode.succeed mkProject |&gt; required "id" int |&gt; required "name" string |&gt; required "tasks" (list taskDecoder) |&gt; required "closed" bool ```
2019-03-26T07:56:19.763600
Nana
elmlang
general
Yea, like that. But the problem of the mixed types comes from the `oneOf` (which is extracted out here), that will need to be separated anyway
2019-03-26T07:59:33.765800
Sharon
elmlang
general
Yeah. Extracting that out to a different function still has the same problem. I think maybe this is not expressable how I think
2019-03-26T08:03:41.767400
Gertrude
elmlang
general
It's not lists' fault, it's that they types make no sense. a non-list decoder would have to look like `or : Parser a -&gt; Parser b -&gt; Parser ?` which makes no sense.
2019-03-26T08:05:13.769000
Gertrude
elmlang
general
Ah! I get it now. I missed the point of <@Nana>'s code. We make taskDecoder an argument, and pass the right decoder when I need it, which thankfully works for this.
2019-03-26T08:09:32.770200
Gertrude
elmlang
general
Good will read. I m trying to avoid the use of ports though
2019-03-26T08:31:39.771100
Leopoldo
elmlang
general
That was the point of the discourse post, to find a solution without ports. In any case, if ports is the way, then use ports.
2019-03-26T08:55:16.771400
Maida
elmlang
general
based on my experience, extreme avoidance of ports is not a good thing. Minimize the use of ports but if the ports solve your problem, use them.
2019-03-26T08:56:36.771600
Maida
elmlang
general
Ok
2019-03-26T09:03:04.771800
Leopoldo
elmlang
general
can anyone recommend me a way to cast a 1 len String to Char?
2019-03-26T09:54:40.772500
Daysi
elmlang
general
<@Daysi> `String.toList x |&gt; List.head`
2019-03-26T09:57:52.773100
Nga
elmlang
general
`String.uncons &gt;&gt; Maybe.map Tuple.first` gives you a `Maybe Char` representing the first unicode codepoint
2019-03-26T09:57:54.773300
Huong
elmlang
general
would give you a Maybe char
2019-03-26T09:57:56.773500
Nga
elmlang
general
`toList &gt;&gt; head` would also work, inded
2019-03-26T09:58:10.773700
Huong
elmlang
general
there's also uncons
2019-03-26T09:58:25.774500
Nga
elmlang
general
what are uncons?
2019-03-26T09:58:37.774900
Daysi
elmlang
general
It's a function `String -&gt; Maybe (Char, String)` that takes the first character off
2019-03-26T09:59:02.775600
Huong
elmlang
general
(if the string isn't empty)
2019-03-26T09:59:16.775900
Huong
elmlang
general
Ok
2019-03-26T09:59:38.776300
Daysi
elmlang
general
You could also write a `NonEmptyString` newtype
2019-03-26T09:59:47.776600
Niesha
elmlang
general
Which would be `(Char, String)`
2019-03-26T09:59:55.776900
Niesha
elmlang
general
Anyone know how I can refactor this into a single line? ```let ( newSession, newCmd ) = Session.redirectWithFlash session in ( { model | divShown = True }, newSession, newCmd ) ```
2019-03-26T10:00:57.777600
Nga
elmlang
general
<https://klaftertief.github.io/elm-search/?q=c%20-%3E%20(a%2C%20b)%20-%3E%20(c%2C%20a%2C%20b)>
2019-03-26T10:01:58.778000
Niesha
elmlang
general
Oh yeah :stuck_out_tongue: That'll do it. Thanks.
2019-03-26T10:03:29.778300
Nga
elmlang
general
`Session.redirectWithFlash session |&gt; \(newSession, newCmd) -&gt; ({model | divShown = True}, newSession, newCmd)`
2019-03-26T10:03:53.778400
Lewis
elmlang
general
Thanks, that also works :slightly_smiling_face:
2019-03-26T10:04:25.778600
Nga
elmlang
general
Elm is supposed to return all headers from a HTTP request right? For some reason the only header I can see is `content-type`, however I can see in my browser console that it has lots of headers like content-length, etc. I'm outputting the headers like so: `Debug.log (String.concat &lt;| Dict.keys metadata.headers) x`, and the only output I get is: `content-type: &lt;function&gt;`. I know it's not a problem with the debug line, because I can do `String.concat ["one","two"]` in my debug line and I'll see "onetwo" in the console, so it seems Elm just isn't getting all headers in its headers dict? Unless I'm missing something weird :confused:. This is for a `Http.BadStatus_`, inside the metadata it has.
2019-03-26T11:00:36.782500
Nga
elmlang
general
Are you doing a CORS request?
2019-03-26T11:10:53.783000
Jin
elmlang
general
Yes I am.
2019-03-26T11:11:02.783200
Nga
elmlang
general
You then have to expose additional header explicitely, see <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>
2019-03-26T11:12:12.784100
Jin
elmlang
general
Thanks. Man, I've been bitten by CORS so many times!
2019-03-26T11:12:37.784500
Nga
elmlang
general
So why can the browser see those headers but Elm can't? Hmm.
2019-03-26T11:14:09.785100
Nga
elmlang
general
Elm will only allow you to access headers exposed with Expose-Headers, but the browser doesn't care?
2019-03-26T11:15:56.786100
Nga