Re: [elm-discuss] File Uploads - as simple as I could manage

2017-11-12 Thread Simon
I updated FileReader today to add some drag drop event handlers that I find 
useful for building an upload system that supports not just the `input [ 
type_ "file" ] []` but also drag n drop of files into a special div. The 
example has been totally reworked to use the main functions
Simon



On Friday, 12 May 2017 15:36:43 UTC+2, Simon wrote:
>
> file-reader was in queue for native approval at 0.16 but that was the 
> point that all native approvals got rejected. To this day there is no easy 
> way to find 'libraries' that use native code, although there are now tools 
> to instal them easily from their github source.
>
>
> On Tuesday, 9 May 2017 12:01:01 UTC+2, Alexandre Galays wrote:
>>
>> "Waiting for Evan". I've heard that before!
>>
>> https://www.youtube.com/watch?v=Wifcyo64n-w
>>
>> On Sunday, May 7, 2017 at 4:12:34 AM UTC+2, Kasey Speakman wrote:
>>>
>>> I don't think there are new native packages being approved. In fact, I 
>>> think more are to get cut soon. We will just have to wait on Evan to put a 
>>> File type into Elm and a Body type for it in the Http module (or something 
>>> like that).
>>>
>>> On Saturday, May 6, 2017 at 7:40:33 PM UTC-5, Witold Szczerba wrote:
>>>>
>>>> You are right, it wouldn't work as I've thought. Native done right is 
>>>> OK, but the problem is someone has to "approve" the project or it won't be 
>>>> available to others by Elm package. I wonder if it's actually doable. 
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: What build system do you prefer for Elm?

2017-11-05 Thread Simon
I use my own starter, which includes hot reloading: 
https://github.com/simonh1000/elm-webpack-starter

On Saturday, 4 November 2017 22:46:29 UTC+1, Pavan Rikhi wrote:
>
> I use webpack to build my app:
>
>
> https://github.com/Southern-Exposure-Seed-Exchange/southernexposure.com/blob/master/client/webpack.config.js
>
>
> NPM to run webpack:
>
>
> https://github.com/Southern-Exposure-Seed-Exchange/southernexposure.com/blob/master/client/package.json#L8-L9
>
>
> And a haskell script to build my client & server, or start the 
> webpack-dev-server & watch/build/run the server:
>
> https://github.com/Southern-Exposure-Seed-Exchange/southernexposure.com/blob/master/manage.hs#L218-L245
>
> https://github.com/Southern-Exposure-Seed-Exchange/southernexposure.com/blob/master/manage.hs#L184-L215
>
> I was using Make for that last step, but find the haskell script much more 
> maintainable.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: keypress events interfering with editor update

2017-10-19 Thread Simon


I think you need to add a variable to your model that records whether the 
editor is being used and then in yout subscription you have 

myKbdSubs model = 
  if model.editorBeingUsed then 
 Sub.none
  else 

On Thursday, 19 October 2017 00:34:35 UTC+2, Dave Doty wrote:

I am using this Ace Editor adapted to Elm: 
> https://github.com/DenisKolodin/elm-ace
>
> However, my problem seems not specific to that editor, but applies to any 
> program that wants to support an embedded editor whose contents can be 
> updated by the program, and also that can respond to global keypress events.
>
> The editor text can be updated either by
>
> 1) the user typing, or
> 2) the program updating the text (e.g., pressing a "load default text" 
> button)
>
> The user can also press some keyboard shortcuts (',' and '.') to do other 
> actions. These are handled by my update function:
>
> update msg model = 
> ...
> KeyMsg keyCode ->
> if keyCode == Char.toCode ',' then
> update Backward model
> else if keyCode == Char.toCode '.' then
> update Forward model
> else
> ( model, Cmd.none )
>
> This is called whenever the user presses any key because of this 
> subscription that uses the elm-lang/keyboard library:
>
> subscriptions model =
> Keyboard.presses KeyMsg
>
> The problem is that all of the keypresses made when editing cause the 
> update function to be called, not just the two that I care about. Most of 
> them are not ',' or '.' so the model is returned unchanged in the else 
> clause above.
>
> But this causes the following problem: in my view function, the editor 
> updates its contents to be whatever the model says the text should be (for 
> instance, the user may press a button that loads some default text):
>
> view model = 
> ...
> Ace.toHtml
> [ Ace.value model.text-- updates editor to display model.
> text
> , Ace.onSourceChange NewText  -- updates model.text to be latest 
> editor contents
> ]
> []
>
> The purpose of onSourceChange above is to trigger another call to the 
> update function, which allows me to update my model text with the new 
> editor contents. In other words, the two lines above are the bi-directional 
> data binding between model.text and the editor's text contents. The 
> second one implies a call to the update function:
>
> update msg model = 
> ...
> NewText newText ->
> ( {model | text = newText}, Cmd.none )
>
> The problem is that the Elm runtime is ordering events so that the text in 
> the editor never gets updated when the user tries to type new text. 
>
> Here is the order of events:
>
>1. User types to edit text in the editor.
>2. Because of the subscription I registered for global keystroke 
>events, Elm runtime calls update with the message KeyMsg indicating 
>which key was pressed.
>3. Model is updated (in the KeyMsg case of my update function) to the 
>"new" model, but most of the time this is identical to the old model since 
>only ',' and '.' actually return a changed model. Importantly, this is 
>the *old* text, not containing the new character that the user typed.
>4. The view function is called, and the Ace.toHtml updates the text 
>contents of the editor to be what the model.text field is... which erases 
>in the editor the new character that the user just tried to enter, since 
>model.text still has the old, pre-keystroke text.
>5. The update function is called with a NewText message, but it's too 
>late. By now the editor has had its new text erased and replaced with the 
>old text. Ideally, this event would have happened in between steps 1 and 
> 2, 
>but steps 2,3,4 seem to happen before this does.
>
> I'm not sure how to get around this. 
>
> *Idea 1:* figure out a way to prevent the update function from being 
> called at all when a keystroke other than ',' or '.' occurs. This is not 
> ideal because then they can't type ',' or '.' in the editor, but it would 
> be a workaround because I could perhaps assign Ctrl+... keys or something.
>
> *Idea 2:* Re-order the updates so that, when the user enters new text in 
> the editor, it is guaranteed that update is called with the NewText message 
> before it is called with the KeyMsg message. I don't know of any way to do 
> this.
>
> *Idea 3:* Re-design how I'm passing messages through the system so that, 
> no matter the order in which messages are delivered, if the user tries to 
> enter new text, eventually that new text makes its way into the model.
>
> *Idea 4:* don't use the Keyboard library to respond to global keypress 
> events, and find something that is more specific to what I want (to give 
> the user a couple of keyboard shortcuts, without calling the update 
> function every time any key is pressed). Suggestions for such a library?
>
​

-- 
You received this message because you are subscribed to the Google 

Re: [elm-discuss] Passing whole state to each view function

2017-08-27 Thread Simon
Just bumping this to the top as it has the best discussion of html lazy 
that I know of in this mailing list and Evan's latest talk (React Rally) 
emphasised lazy there is such a way that I think I had better start using 
it better

On Wednesday, 2 August 2017 05:17:01 UTC+2, ajs wrote:
>
> Hi Mark, feel free to hit me up on Slack sometime to discuss further. My 
> last two messages to this list have had more than one week delay in posting 
> (ignore the timestamp, I'm posting this on Friday July 21), so that might 
> be easier. 
>
> I discussed these ideas quite a bit with @ilias and he made a rather 
> interesting example of doing some things relating to state access: 
> https://github.com/zwilias/elm-disco
>
> I'm a firm believer that view functions should only receive data that they 
> directly interact with, and nothing more. I've just found that to be a much 
> better way to reason about interfaces.
>
> On 21 Jul 2017, at 19:04, Mark Hamburg  
> wrote:
>
> Per the other thread discussing this this morning, I don't know that 
> passing the whole data model to all of the view-side functions is that 
> horrendous. (We pass around a UXConfig structure in all of our views to 
> provide access to translation functions amongst other things and the 
> biggest pain is that I'm not certain that making it he first parameter by 
> convention was the right choice.) Passing the whole data model feels icky, 
> but you can document the dependencies using different modules to access 
> different parts of the data model and you can still keep data model 
> mutation out of the views by emulating the command mechanism.
>
> That said, there are, definitely friction points where being able to 
> subscribe to pieces of the data model would be a significant improvement. 
> See my other message for some examples of these. But the friction is not in 
> needing to pass the whole data model through the rendering process.
>
> Mark
>
> On Fri, Jul 21, 2017 at 6:55 AM ajs  
> wrote:
>
>> > However, the downside of doing passing the entire model everywhere is 
>> that you have to keep the entire model in your head when looking at any of 
>> your view functions.
>>
>> This is correct, but how can you avoid passing the whole model to all 
>> views if the data model isn't structured similarly to your view hierarchy? 
>> The idea of doing pre-processing on your data into a view-friendly 
>> structure seems to add overhead and complexity, while also more or less 
>> duplicating your view structure in two places: the view stack, and the view 
>> data.
>>
>> We have found that as apps grow in size, it is unreasonable to couple a 
>> data model's internal structure to the requirements of a UI, and thus 
>> passing The whole model is the only valid option for most view functions. 
>> The exception are leaf nodes down the line that have few or no children, in 
>> which case they can receive focused inputs only.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
> -- 
> You received this message because you are subscribed to a topic in the 
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/elm-discuss/F5pdcsls1Zc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> elm-discuss...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Developing with Webpack 3 and hotloading

2017-06-30 Thread Simon
hot-loading is such a productivity boon! :-)

If you have any extra webpack goodness that it would make sense to add to 
my starter, feel free to submit a PR. 

On Tuesday, 27 June 2017 15:47:58 UTC+2, Tolga Paksoy wrote:
>
> Thank you so much. I've been looking into the hot loader, and wasn't quite 
> able to figure out why hot-loader kept losing state on compile errors.
>
> Apparently, this is needed (as pointed out in your webpack.js file)
>
> new webpack.NoEmitOnErrorsPlugin()
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Developing with Webpack 3 and hotloading

2017-06-22 Thread Simon
I've just upgraded the dev environment I use for my professional work to 
Webpack 3 (+ SCSS and Bootstrap 4). The pack is open source if anyone else 
wants to use it too.

https://github.com/simonh1000/elm-webpack-starter

Simon


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Integrating Elm with Web Components / Polymer

2017-05-31 Thread Simon


One interesting thing I found as I experimented this morning is that React 
components can be wrapped up 
 to be web 
components, which might make react components more accessible from Elm (at 
present it is not straightforward 
). 
Here’s a basic example of the pattern. My experience of React is very 
limited, so I’m wondering how scalable this example could be for the react 
components people get excited about (not sure which those are though)?

import React from 'react';
import ReactDOM from 'react-dom';

var mountPoint = document.createElement('div');

const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
this.createShadowRoot().appendChild(mountPoint);

const name = this.getAttribute('name');
myRender({name});
}
},
attributeChangedCallback: {
value: (attrName, oldVal, newVal) => {
if (attrName == "name") {
myRender({newVal});
}
}
}
});

function myRender(s) {
ReactDOM.render(s, mountPoint);
}

document.registerElement('x-hello', {prototype: proto});

On Friday, 23 September 2016 14:28:06 UTC+2, Peter Damoc wrote:

I've been trying to get this to work but I don't have enough knowledge. 
>
> The main problem I'm facing seams to be one of setup/deployment. 
>
> Can someone help with a simple example that uses paper-date-picker
> https://customelements.io/bendavis78/paper-date-picker/
>
> I'm looking for the following:
>
> - a file structure/setup for the project that allows development of an Elm 
> program using paper-date-picker where one can see the same output in both 
> Chrome and Firefox
> - a way capture a notification for the date change
>
> less important but useful: 
> - a way to create some kind of a deliverable (something that one can put 
> on some webhosting and have it work)  
>
> Regarding the event from the component I've found 
> https://github.com/kevinlebrun/elm-polymer
> but I was unable to transfer the knowledge shown there for how to listen 
> to changes inside the web component. 
>
> Setting the date value with attribute (counter-polymer-inside-elm) 
> actually proved to be very easy and it worked without needing the port. 
> Getting informed about the date change happening inside the widget 
> however, did not work. 
>
> I tried replacing "value" with "date" in the event attribute and the json 
> decoder  (replacing Json.int with Json.string) but... it did not work. 
>
> Here are the files I have so far: 
> https://gist.github.com/pdamoc/48c6f7dd2f7fec44bdd3262f269f635c
>
>
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] File Uploads - as simple as I could manage

2017-05-12 Thread Simon
file-reader was in queue for native approval at 0.16 but that was the point 
that all native approvals got rejected. To this day there is no easy way to 
find 'libraries' that use native code, although there are now tools to 
instal them easily from their github source.


On Tuesday, 9 May 2017 12:01:01 UTC+2, Alexandre Galays wrote:
>
> "Waiting for Evan". I've heard that before!
>
> https://www.youtube.com/watch?v=Wifcyo64n-w
>
> On Sunday, May 7, 2017 at 4:12:34 AM UTC+2, Kasey Speakman wrote:
>>
>> I don't think there are new native packages being approved. In fact, I 
>> think more are to get cut soon. We will just have to wait on Evan to put a 
>> File type into Elm and a Body type for it in the Http module (or something 
>> like that).
>>
>> On Saturday, May 6, 2017 at 7:40:33 PM UTC-5, Witold Szczerba wrote:
>>>
>>> You are right, it wouldn't work as I've thought. Native done right is 
>>> OK, but the problem is someone has to "approve" the project or it won't be 
>>> available to others by Elm package. I wonder if it's actually doable. 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: List of all members of a union type

2017-05-05 Thread Simon
I had a different use case for the same basic idea. With GraphQL we have a 
sort-of typed query language that returns clearly defined json structures. 
In an ideal world therefore you should be able to define an Elm data 
structure (sum or union type) and for library functions to be able to 
create the query string and the json decoder for you. I may be over 
optimistic, and such things may not even be possible in other ML-family 
languages, but it felt like something that should be automatable



On Thursday, 4 May 2017 04:14:03 UTC+2, Matt Hughes wrote:
>
> At first I wondered if a type is really what you need for this 
> application, as opposed to say a list of strings. Anyway one idea is to 
> write a function to explicitly convert the type to a string. I think this 
> is better than simply taking the type name and making it a string because 
> the string representation may need spaces or other punctuation. Using an 
> explicit case means the compiler won't let you forget if you add a new 
> type. 
>
> module Main exposing (..)
>
> import Html exposing (Html, text)
>
> type Province = Alberta | BritishColumbia | Saskatchewan
>
> toString : Province -> String
> toString p =
> case p of
> Alberta -> "Alberta"
> BritishColumbia -> "British Columbia"
> Saskatchewan -> "Saskatchewan"
>
> main : Html a
> main =
> text (toString Alberta)
>
> mch
>
> On Tuesday, May 2, 2017 at 9:44:34 PM UTC-6, Matthew Buscemi wrote:
>>
>> I have run into a problematic use case a couple of times, and based on 
>> Slack discussions earlier today, it seems I'm not alone.
>>
>> The situation occurs when, for some reason, I need to maintain a list of 
>> all constructors of a union type. The example given in Slack by mltsy:
>>
>> type State = Alabama | Alaska | Arizona | Arkansas | ...
>>
>> allStates = [ Alabama, Alaska, Arizona, Arkansas, ...]
>>
>> stateSelectBox : List State -> Html Msg
>> stateSelectBox states =
>>   let stateValues = List.map toString states
>>   in ...
>>
>> In the example above, simply turning allStates into a list of strings 
>> would be fine for this particular use case, but in the context of a larger 
>> system, it could be inadequate–other functions besides stateSelectBox may 
>> want to utilize the power of performing a case over the union type. 
>> However, the above solution is also structurally undesirable–if a new type 
>> is added to State, then the programmer must also remember to update 
>> allStates separately. The duplication and tight coupling are disconcerting, 
>> and yet I can't see a viable alternative that preserves the power of types 
>> without incurring the duplication.
>>
>> I have wondered if a language-level construct that takes a union type and 
>> returns a list of all constructors for that type would be appropriate for 
>> Elm. Just a thought.
>>
>> - Matt
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Poll for Intermediate to Advanced topics that people struggle with

2017-05-02 Thread Simon
with should read 'without'

On Tuesday, 2 May 2017 21:31:39 UTC+2, Simon wrote:
>
> Like Peter, I think the key issue is how to build a large app with 1000 
> line files.
>
> On authentication, this might help: 
> http://simonh1000.github.io/2016/05/phoenix-elm-json-web-tokens/
>
> On Tuesday, 2 May 2017 16:10:03 UTC+2, Alan McCann wrote:
>>
>> I echo Peter Damoc's entry + authentication (e.g. JWT)
>>
>> On Monday, April 24, 2017 at 10:06:53 AM UTC-4, Jeff Schomay wrote:
>>>
>>> Hello,
>>>
>>> I am considering doing some training material on working with Elm in 
>>> production.  I want to focus on areas that people struggle with after they 
>>> are already familiar with Elm.  What concepts continue to confuse you? 
>>>  What product requirements have been difficult to achieve with Elm?  What 
>>> is most painful about your Elm codebase?
>>>
>>> Some topics I have already thought of:
>>>
>>> - decoders
>>> - debouncing (http autocomplete input field for example)
>>> - scroll to element
>>> - testing
>>> - unwieldy update functions
>>> - api design
>>>
>>> If you have anything you'd like me to consider, please add it to the 
>>> list.  Thank you!
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Poll for Intermediate to Advanced topics that people struggle with

2017-05-02 Thread Simon
Like Peter, I think the key issue is how to build a large app with 1000 
line files.

On authentication, this might 
help: http://simonh1000.github.io/2016/05/phoenix-elm-json-web-tokens/

On Tuesday, 2 May 2017 16:10:03 UTC+2, Alan McCann wrote:
>
> I echo Peter Damoc's entry + authentication (e.g. JWT)
>
> On Monday, April 24, 2017 at 10:06:53 AM UTC-4, Jeff Schomay wrote:
>>
>> Hello,
>>
>> I am considering doing some training material on working with Elm in 
>> production.  I want to focus on areas that people struggle with after they 
>> are already familiar with Elm.  What concepts continue to confuse you? 
>>  What product requirements have been difficult to achieve with Elm?  What 
>> is most painful about your Elm codebase?
>>
>> Some topics I have already thought of:
>>
>> - decoders
>> - debouncing (http autocomplete input field for example)
>> - scroll to element
>> - testing
>> - unwieldy update functions
>> - api design
>>
>> If you have anything you'd like me to consider, please add it to the 
>> list.  Thank you!
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Elm Textfield + a barcode scanner

2017-04-28 Thread Simon
not sure whether this is relevant but can you take advantage of the 
difference between the `oninput` and `onchange` events in a text field?


On Friday, 28 April 2017 07:51:48 UTC-7, Chris Van Vranken wrote:
>
> I'm using a barcode scanner to enter data into an elm textfield.  The 
> barcode scanner basically works like a keyboard with a user that makes very 
> rapid keystrokes.  This rapid entry causes random characters to be missing 
> in the textfield.  If the scan is supposed to enter "50494'', one or more 
> of these characters will often be missing.  Using the debugger I see that 
> my model has values for that field that change from "5" to "50" to "504" to 
> "509" to "5094", but it should be "5" to "50" to "504" to "5049" to 
> "50494"  So it ends up replacing "504" with "509" instead of with "5049". 
>  I believe this is a threading issue where two events are firing in 
> parallel instead of in sequence, and both events are starting with the same 
> model data ("50") with the output of one event replacing the output of the 
> other, when instead the output model for one event should be the input for 
> the next event.  Is this a bug in Elm?  How do I fix this?
>
> Thanks,
> Chris
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Structuring model and messages | Debouncing in a large app

2017-04-21 Thread Simon
THANKS SO MUCH!

I don't know that whether its true that effects modules can't be published 
on elm-package - this one at least has no native code which I know to be a 
blocker.

But as we both noted, there are times when the TEA does not, and arguably 
cannot, provide a good developer experience. It is such a shame that 
effects modules are so frowned upon.




On Thursday, 20 April 2017 22:00:50 UTC+2, jsch...@pivotal.io wrote:
>
> My comment is RE debouncing in particular.  I too have been frustrated to 
> see so many debouncing libraries.  The problem is that none of them are 
> great, because debouncing makes the most sense to solve as a managed 
> effect, rather than in user-space.  And, effect packages can't be published 
> afaik.  There are quite a few of this type out there on github.  The one 
> that we use to good effect is here: 
> https://github.com/tracker-common/elm-debouncer/blob/be3bd02ccac6b71b0088c08359b3f45b5ae7c4dc/src/Debouncer.elm
>  
> (sorry for the outstanding PR).  It provides an api very similar to 
> Task.attempt, but the task given to it will be debounced.  There are 
> similar ones that deal with Msg instead of tasks (
> https://github.com/unbounce/elm-debounce), but I like to keep my effects 
> in tasks as long as possible so I can chain/map them as needed before 
> sending them out.
>
> On Thursday, April 20, 2017 at 3:18:28 AM UTC-6, Simon wrote:
>>
>> First of all - 6 debouncing libraries! Would be great to see elm-package 
>> be able to surface github stars directly (or some other means of identify 
>> the most-likely-to-be-good library)
>>
>> My question though is the following. The type signature of a debounce 
>> state is DebounceState Msg. I.e. it needs the message type as that’s 
>> what it is going to send back later.
>>
>> But in a large app, I usually have the model in 1 file and import that 
>> into my update/view files and it is in the latter that I define the type 
>> Msg.
>>
>> I’m quickly going to get a singularity if I try to import my Msgs into 
>> my model.
>>
>> I’ve never separated out my Msgs before into a separate file but can see 
>> some other benefits. But there will also be costs too.
>>
>> So I was wondering 
>>
>>- what other experiences people had had with separating out Msgs 
>>- whether there was an alternative to this to handle the issue at 
>>hand - debouncing (all of the examples in the libraries are tiny single 
>>file ones inevitably) 
>>
>> ​
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: WYSIWYG functionality

2017-04-18 Thread Simon
If you haven't already seen https://www.youtube.com/watch?v=EEF2DlOUkag 
then it might be useful for you

On Wednesday, 12 April 2017 16:46:07 UTC+2, Daniel Wehner wrote:
>
> It could be really interesting to also experiment with looking at 
> https://draftjs.org/ / providing a port or a in elm implementation of it.
>
> https://github.com/thebritican/elm-editor seemed to have tried that, but 
> there seemed no progress on that in the meantime.
>
> Am Mittwoch, 12. April 2017 06:20:44 UTC+1 schrieb Michael Lebow:
>>
>> I'm working on something that requires some WYSIWYG editor like 
>> functionality.
>>
>> The way I'm thinking about it is inspired by the Basecamp Trix editor and 
>> the Medium editor.  Capture input events, create an internal model 
>> representing the content, and then re-render.  (Avoiding execCommand and 
>> the differences that can cause with different browsers)
>>
>> ContentEditable seems to be the only way to accomplish this.  A simple 
>> input will not allow for some of the rich text features I plan to 
>> implement. 
>>
>> I have started an implementation of this and get stuck with the problem 
>> of needing to manually set the cursor position after text is typed and the 
>> html re-renders.  (Currently, it jumps to the front of the content editable 
>> div after every keystroke)  It looks like maybe at one point in time this 
>> was a problem with simple text inputs in elm too??  (
>> https://groups.google.com/forum/#!topic/elm-discuss/I2JleY8bD7c)  I'm 
>> curios if anyone can direct me to the history of that bug and what the 
>> solution was.
>>
>> This content editable cursor position issue is also brought up here: 
>> https://github.com/elm-lang/virtual-dom/issues/23
>>
>>
>> From my reading on this, it seems other's have brought up the idea of 
>> making an WYSIWYG editor with Elm, but get stuck with the inability to do 
>> things like window.getSelection() or interact with that selection e.g. 
>> Selection.addRange()
>> This is brought up here - 
>> https://groups.google.com/forum/#!topic/elm-dev/169IJRJsW6Q - and 
>> seemingly left unresolved.
>>
>> If I'm willing to do the legwork, what's the best way to accomplish this 
>> in Elm?  If it's not currently possible with only Elm, what's the next best 
>> thing?  Is there a way I can build the APIs that Elm currently lacks for my 
>> own use until the community determines the best way to incorporate them 
>> into Elm?  Should I be reaching for Ports?
>>
>> Thanks in advance!
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Task ports: A proposal to make it easier to integrate JS with Elm.

2017-04-14 Thread Simon
+1 for Task ports.

On Friday, 14 April 2017 20:32:24 UTC+2, Nicholas Hollon wrote:
>
> The process:
>
> 1. Share your ideas, experience, & code on elm-discuss.
> 2. Accept that you have no direct influence over what Evan works on next.
> 3. Look at the release history  for Elm. Notice 
> that changes happen slowly. Notice that improvements to the JavaScript 
> interface (ports, tasks, subscriptions) are spaced out by at least a year. 
> Notice that 0.17 has only been out for about a year.
> 4. Remember that things are going to get better! Just because something 
> isn't being worked on right this minute doesn't mean that it isn't going to 
> be improved in the future.
> 6. Do things in life that make you happy. If it upsets you that Elm lacks 
> something you think is super important, maybe take a break and come back 
> later.
>
>
>
> On Friday, April 14, 2017 at 10:24:46 AM UTC-7, Conner Ruhl wrote:
>>
>> What is the process for requesting these sort of features? Is there one?
>>
>> On Saturday, August 13, 2016 at 10:31:07 AM UTC-5, James Wilson wrote:
>>>
>>> The problem
>>>
>>> ports as they stand are fundamentally incompatible with Tasks. Being 
>>> backed by Cmd's, they are harder to compose. A frustration of mine is that 
>>> often we are directed to "just use ports" when a proper interface to some 
>>> native API is not yet available, but this leads to our Msg types growing 
>>> and more significant changes being required when eventually the proper 
>>> interface is made available.
>>>
>>> Also, many JS interop things I find myself wanting to do are 
>>> fundamentally one-shot functions which I expect a result back into Elm from 
>>> immediately, or otherwise just want to compose with other Task based 
>>> things. Some examples that come to mind of one-shot tasks you may want to 
>>> compose rather than use the streaming interface that ports provide:
>>>
>>>- Getting items from local/sessionStorage
>>>- .. really, most things involving working with the Web API that 
>>>arent yet implemented in Elm.
>>>- Embedding JS widgets into Elm elements
>>>- Using a JS library for doing things like hashing passwords or 
>>>obtaining some data back from some custom service
>>>- Interacting with things like Electron for creating apps that can 
>>>run in the desktop and interact with the filesystem etc.
>>>
>>>
>>> The solution
>>>
>>> Task ports. The idea is that these are defined the same way that Ports 
>>> in elm currently are, but they return a Task type rather than a Cmd or Sub 
>>> type. On the JS Side, we attach a function to the Elm app that returns a 
>>> Promise, and on the Elm side we wait for the Promise returned to reject or 
>>> resolve, and marhsall the error or result from the promise into the error 
>>> or result type required by the Task type of the port.
>>>
>>> Let's see how this might work:
>>>
>>>
>>> *Ports.elm:*
>>>
>>> port apiSession: Task String SessionId
>>>
>>>
>>>
>>> *Main.elm:*
>>>
>>> import Ports
>>> import Json.Decode as Decode
>>> import Task exposing (andThen)
>>>
>>>
>>> -- get an API session from JS land and make an http request using it
>>> -- given some path and a decoder to decipher the result:
>>> apiRequest : String -> Decoder a -> Task ApiError a
>>> apiRequest path decoder =
>>>   let
>>> headers sessId =
>>> [ ("Content-Type", "application/json")
>>> , ("MyApp-SessionId", sessId)
>>> ]
>>>
>>>
>>> req sessId = Http.send Http.defaultSettings
>>> { verb = "POST"
>>> , headers = headers sessId
>>> , url = path
>>> }
>>>
>>>
>>> decodeResponse res = Decode.decodeString decoder -- ...handle error 
>>> etc
>>>   in
>>> Ports.apiSession `andThen` req `andThen` decodeResponse
>>>
>>>
>>> *App.js:*
>>>
>>> Elm.Main.ports.apiSession = function(){
>>> return new Promise(function(resolve,reject){
>>>
>>>
>>> var sess = localStorage.getItem("sessionId");
>>> if(!sess) reject("NO_SESSION");
>>> else resolve(sess);
>>>
>>>
>>> });
>>> }
>>>
>>> var app = Elm.Main.fullscreen();
>>>
>>>
>>>
>>>
>>> Here, we use a tiny bit of JS to access localStorage and pull out a 
>>> session ID. This function is used whenever the apiRequest Task is performed 
>>> in Elm, and composes nicely into our apiRequest without the need for a 
>>> complicated effect manager or threading a sessionId through everywhere just 
>>> because we need to get it from a Cmd based port.
>>>
>>> One of the nice things about this is that there is minimal refactoring 
>>> to do for those things that do eventually receive coverage in the Elm Web 
>>> API - you're just swapping out Tasks for other Tasks. As the Web API will 
>>> always be changing, I think that having a nice way to make JS polyfills 
>>> like this will always have some value, let alone for interacting with 
>>> libraries written in JS that haven't or won't ever be ported to Elm.
>>>
>>> Elm 

[elm-discuss] Re: Checking JWT Token expiry and Time

2017-04-02 Thread Simon
Sounds like you need this function 
http://package.elm-lang.org/packages/simonh1000/elm-jwt/5.0.0/Jwt#isExpired

If there is something missing in elm-jwt, let  me know and I'll see if it 
can be added (or you could send a PR)

On Sunday, 2 April 2017 05:44:29 UTC+2, Richard Wood wrote:
>
> Hi All
>
> I'm working on a base application involving authentication, Auth0 and AWS 
> access. There's a lot of useful starter scripts and examples around - hats 
> off to the community - so I'm basically pulling stuff together for 
> server-less projects and so I can learn elm and authentication.
>
> I'd be keen for anyone to have a look and give me some feedback:
> Elm repository https://github.com/rwoodnz/elm-base
> AWS repository https://github.com/rwoodnz/aws-base
>
> *My question*
> On entry I pop up the Auth0 lock if the user has not got an existing 
> token. My next stage is to add a check or checks for Token expiry. I want 
> to do that in the code and not make a call to Auth0 or rely on a bad 
> response from the API.
>
> I've found the very useful-looking JWT library and the Time functionality 
> and am trying not to despair at the amount of code it may take!
>
> Is there a simpler way? Should I just port out to Javascript as it would 
> only be a little function there? I'm really trying to avoid that in 
> principle and so as to force my Elm learning.
>
> Richard
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] How to see which file is slowing compilation?

2017-03-31 Thread Simon
Hi, I read recently that `case (x,y,z) of ` is going to slow compilation. 
perhaps other things do too. I see my compilation times slowly creeping 
upwards (1 LOC) and thought about trying to tackle issues. But other 
than `case` I don't know what else to look at and - more importantly - I 
can't readily see in the compilation output which files are taking the 
longest to parse.

Any hints?

Simon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Collecting use cases for File, ArrayBuffer and TypedArrays/DataViews

2017-03-30 Thread Simon
My company uses websockets for mobile apps and thus wants to save on 
bandwidth. As a result all websocket traffic is encoded using msgpack, but 
the current library cannot handle that - presumably because of Elm's lack 
of underlying support for binary data.


On Thursday, 28 July 2016 23:17:51 UTC+2, Daniel Bachler wrote:
>
> I'd love to see support for the File and ArrayBuffer Apis, and maybe 
> TypedArrays/DataViews as well. IMHO they are an important piece of the Web 
> Platform that is still missing in Elm.
>
> Evan suggested collecting concrete use cases to guide the design. I would 
> like this thread to be the starting point of this effort. I would like to 
> ask anyone who would also like this feature or who has substantial 
> experience using either Api to add use cases or comment here so that we can 
> try to define the user story for both apis. From there, we could decide 
> what we would like to see supported and what, if anything, we don't need 
> for now and suggest Elm Apis.
>
> I have two stories from a side project of mine. It is a slideshow editor 
> that allows the user to select photos and audio files from the local 
> system, uploads them to a web service, let's the user arrange and 
> manipulate photos and music and then share the result with others. For 
> this, I have two immediate use cases plus some more ideas:
>
> *Upload local files as binary blob to AWS S3*
>
> In my current, (hacky) version, I use the FileReader api (via simonH1000's 
> filereader library) to read the content of a file into an ArrayBuffer, 
> (represented as Json.Value in Elm) then use a modified version of elm-http 
> to upload the content of the ArrayBuffer to an S3 storage bucket.
>
> *Download mp3 files, decode them and play them back via the AudioApi*
>
> Currently I do this with my modified http library to download the mp3 file 
> into an arraybuffer, then pass the resulting arraybuffer through a port to 
> some native javascript that then uses the Audio Api to decode the mp3 file 
> into a playable audiobuffer.
>
> *Parsing or otherwise processing local text files. *
>
> For another project I would be interested in reading and parsing 
> Swagger/OpenAPI definition files and then providing a UI to compare rest 
> apis. Since the processing will be done on simple Strings, this would only 
> require FileReader support (specifically the readAsText method). This would 
> already work with the FileReader library as is (though that one is not 
> available on package.elm-lang.org because it contains native code and is 
> not whitelisted).
>
> *TypedArrays and DataViews*
>
> I haven't worked with these yet, but I can anticipate some cases that 
> would be interesting:
>
> *Parsing/manipulating of binary data via the ArrayBuffer api.*
>
> One case I personally would like to do with this, is to parse the Exif 
> header of the jpeg files the user loaded from the local file system. My 
> slideshow could then display metadata information without roundtripping to 
> the server.
>
> *Create geometry for WebGL in the form of Vertex Buffers*
>
> *Generating sound/music by writing raw audio samples*
>
> These could then be played back via the Web audio apis.
>
>
> Please add your own ideas to this thread. Once we have compiled a list of 
> use cases, we can look at the JS Apis available under the Web Platform for 
> Files, ArrayBuffers, Typed Arrays etc. and think how these could be exposed 
> to Elm. 
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Support for binary data

2017-03-30 Thread Simon
My use case:

My company uses websockets for mobile apps and thus wants to save on 
bandwidth. As a result all websocket traffic is encoded using msgpack, but 
the current library cannot handle that.



On Tuesday, 12 January 2016 01:32:43 UTC+1, Evan wrote:
>
> I have been drafting Blob and ArrayBuffer APIs, but I wasn't sure who 
> needed them.
>
> What is your particular use case?
>
> On Mon, Jan 11, 2016 at 4:55 AM, John Watson  > wrote:
>
>> Can anyone tell me what the plans are for supporting binary data in elm?  
>> I'm thinking of a Byte (and some sort of Byte Array) type and also 
>> implementing Blob in HTTP responses. 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: 'Native' -> 'Kernel': a msgpack example

2017-03-26 Thread Simon
Ok, I hope that this is just a naming change, but spent too much time in 
politics not to fixate on choice of language issues!
But compared to other compile-to-js languages, Elm is seemingly the one 
that puts the most the hurdles ahead of easily using the libraries 
available in the world's most popular language.



On Saturday, 25 March 2017 02:52:20 UTC+1, Kasey Speakman wrote:
>
> Yeah, I regretted posting that 2nd half. I don't use any native modules 
> myself except the one to return decoders out of ports. And I was getting by 
> without it via ports, although somewhat less optimally. Maybe some people 
> really need native stuff, though. I haven't. (And I'm willing to monkey 
> patch what I use native for now if need be.)
>
> On Friday, March 24, 2017 at 1:48:01 PM UTC-5, Kasey Speakman wrote:
>>
>> Indeed, the post mentions renaming Native to Elm.Kernel and ending the 
>> native module whitelist (sortof). Expectation management.
>>
>> User native module blocking was not mentioned. In our current Javascript 
>> ecosystem such a thing would make Elm non-viable.
>>
>> Well, except that repo-forking and monkey-patching exist.
>>
>> On Friday, March 24, 2017 at 6:42:34 AM UTC-5, Rupert Smith wrote:
>>>
>>> On Thursday, March 23, 2017 at 8:15:51 PM UTC, Simon wrote:
>>>>
>>>> It's pretty clear that these practices are frowned upon, but the shift 
>>>> to 'kernel' sounds like a plan to squeeze the pragmatic programmer's 
>>>> options further. I hope that's not the case.
>>>>
>>>
>>> I think all that is happening is that Native is being renamed to Kernel 
>>> to reduce confusion. At the moment when we say 'Elm' and 'native' in the 
>>> same sentence we could mean an Elm Native module used to implement its 
>>> kernel, or native javascript code through ports.
>>>
>>> I can't be certain of the details but I think your function would just 
>>> be re-written as:
>>>
>>> var _user$project$Kernel_Msgpack = function() { ... }
>>>
>>> But you won't be able to publish it officially and will have to use 
>>> elm-github-install.
>>>
>>> It makes sense to me anyway, the 'kernel' needs to be carefully managed 
>>> as the language takes shape.
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] 'Native' -> 'Kernel': a msgpack example

2017-03-23 Thread Simon
On elm-dev I get the impression that bigger barriers are being built to 
towards javascript interop.

I think building the barriers before the webapi is provided in Elm is the 
wrong way around, but that's not the only case where practical needs are at 
risk.

Consider msgpack - a sort of compressed json. It's well specified but today 
not much used. No one has written a library for it in Elm, but there is a 
well-tested JS one. The encoding is simply calculations, so in the normal 
run of things this should be a synchronous operation. If ports returned 
Tasks this would not be a huge issue, but they return Commands and thus 
force you back around the update loop (and the creation of an extra Msg, 
which makes code intent less transparent).

The work around is a native file along the lines of (or see this NoRedInk 
library ):

```
var _user$project$Native_Msgpack = function() {

function encode(k) {
return msgpack.encode(k.kwd);
}
}
```

It's pretty clear that these practices are frowned upon, but the shift to 
'kernel' sounds like a plan to squeeze the pragmatic programmer's options 
further. I hope that's not the case.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Elm and contenteditable

2017-02-26 Thread Simon
For what I needed to do (convert an enter into a 'finished editing' action 
i found quite a nice solution

https://stackoverflow.com/questions/42390708/elm-conditional-preventdefault-with-contenteditable

In brief, I catch the keydown event but convert anything other than an 
enter in to json decode fail, so that it does not reach the update loop. An 
enter is caught, with preventDefault applied, and is passed to update as a 
finished editing action, which I pass to Dom.blur and then catch the blur 
event and use that to cause the model to updated.

Simon


On Sunday, 26 February 2017 09:11:51 UTC+1, Vincent Jousse wrote:
>
> The best workaround I've found is to use a webcomponent wrapper (only 
> compatible with chrome): 
> https://github.com/vjousse/the-transcriber/blob/webcomponents/src/static/js/custom-text-editor-element.js
>
> I'm using a custom attribute called "content" that is mapped to my Elm 
> Model. With this solution I've got the best of both worlds: Elm is managing 
> the DOM of my contenteditable element while being able to write custom 
> behavior in javascript for it.
>
> It is based on this talk by Richard Feldman: 
> https://www.youtube.com/watch?v=ar3TakwE8o0
>
> 2017-02-25 11:41 GMT+01:00 Witold Szczerba <witold...@gmail.com 
> >:
>
>> One trick I have learned when integrating date range picker is that you 
>> can push data from component to Elm using custom HTML events instead of 
>> sending data through a port(s).
>> I have described it shortly here:
>>
>> https://www.reddit.com/r/elm/comments/5uqa13/those_fancy_date_pickers_in_elm_watch_this_no/
>>
>> input [ class "form-control date-range" , value <| formatMaybeDuration 
>> item.duration , onDateRangePicker DurationChanged *-- see demo for 
>> details* ] []
>>
>> Regards,
>> Witold Szczerba
>>
>> On Fri, Feb 24, 2017 at 4:30 PM, Josh Szmajda <jos...@gmail.com 
>> > wrote:
>>
>>> I'm working with http://github.com/Voog/wysihtml, integration has been 
>>> pretty alright.. Still very much in the figuring things out stage for my 
>>> app but here are some key snippets:
>>>
>>> Ports:
>>> ```
>>> port startEditor : (String, String, String) -> Cmd msg
>>> port stopEditor : String -> Cmd msg
>>> port editorChanges : (String -> msg) -> Sub msg
>>> port selectionChange : (Selection -> msg) -> Sub msg
>>> ```
>>>
>>> Selection:
>>> ```
>>> type alias Selection =
>>>   { text : String
>>>   , t : Float
>>>   , r : Float
>>>   , b : Float
>>>   , l : Float
>>>   }
>>> ```
>>>
>>> WYSIHtml View:
>>> ```
>>> module Wysihtml.View exposing (wysiToolbar, wysiEditor)
>>>
>>> import Html exposing (..)
>>> import Html.Attributes exposing (id, attribute, class)
>>>
>>> wysiToolbar : a -> Html a
>>> wysiToolbar msg =
>>>   div [ id "wysi-toolbar" ]
>>> [ a [ class "bold", command msg "bold" ] [ text "B" ]
>>> , a [ class "italic", command msg "italic" ] [ text "I" ]
>>> , a [ class "h1", command msg "formatBlock", commandValue msg "h1" ] 
>>> [ text "H1" ]
>>> , a [ class "p", command msg "formatBlock", commandValue msg "p" ] [ 
>>> text "P" ]
>>> , a [ class "ul", command msg "inserUnorderedList" ] [ text "list" ]
>>> ]
>>>
>>> wysiEditor : a -> Html a
>>> wysiEditor msg =
>>>   div [ id "wysi-editor", dataPlaceholder msg "Start editing" ] []
>>>
>>>
>>> dataPlaceholder : a -> String -> Attribute a
>>> dataPlaceholder msg data =
>>>   attribute "data-placeholder" data
>>>
>>> command : a -> String -> Attribute a
>>> command msg command =
>>>   attribute "data-wysihtml5-command" command
>>>
>>> commandValue : a -> String -> Attribute a
>>> commandValue msg value =
>>>   attribute "data-wysihtml5-command-value" value
>>> ```
>>>
>>> index.html wiring:
>>> ```
>>> app.ports.startEditor.subscribe(function(){
>>>   var editor = arguments[0][0];
>>>   var toolbar = arguments[0][1];
>>>   var initialText = arguments[0][2];
>>>   // todo change setTimeout to MutationObserver
>>> 

[elm-discuss] Re: webpack hotloading: compile errror leads to loss of state

2017-02-25 Thread Simon
Aha, that's promising

I have my own starter https://github.com/simonh1000/elm-hot-loading-starter 
and have tried https://github.com/halfzebra/create-elm-app and both 
experienced the issues I described. I will take a look at what you do

Simon

On Saturday, 25 February 2017 18:13:09 UTC+1, Austin Bingham wrote:
>
> Is this with elm-webpack-loader, or some other package? I use 
> elm-webpack-loader and the webpack-dev-server, and it definitely recovers 
> after a broken compilation. You can see my configuration here if that 
> helps: https://github.com/abingham/accu-2017-elm-app
>
> On Saturday, February 25, 2017 at 4:56:59 PM UTC, Simon wrote:
>>
>> I have tried webpack directly and some of the starters, but I can't find 
>> a way to use hotloading after making a change that led to a compiler error. 
>> It only works if you write perfect code and recompile. If you have an 
>> error, then when these have been fixed the page reloads with the default 
>> state.
>>
>> Are there any solutions for this?
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Elm and contenteditable

2017-02-24 Thread Simon
I'm also trying to work with contenteditable. I have a basic system working 
with pure Elm, in that I can click on a field to edit it and then click 
elsewhere with blur causing an update of the model. But the challenge I 
face is detecting an enter key and using that save the updated value and 
blur the current field. I seem to be getting some virtual DOM issues.  

Anyway I have an Ellie at https://ellie-app.com/tnXL92zwvka1/3 and if 
anyone can help, I'd love to know

Simon

On Tuesday, 27 September 2016 16:35:04 UTC+2, Girish Sonawane wrote:
>
> Instead of onChange, you can try using Events.on 
> http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Events#on
>
>
> On Tuesday, August 30, 2016 at 3:16:12 PM UTC+5:30, Peter Damoc wrote:
>>
>> I've tried a naive implementation in Elm but, for some reason, it doesn't 
>> work (events are not fired for divs that have content editable) 
>>
>> import Html exposing (..)
>> import Html.Attributes exposing (..)
>> import Html.App exposing (beginnerProgram)
>> import Html.Events exposing (on)
>> import Json.Encode as JE
>> import Json.Decode as JD exposing ((:=))
>>
>>
>> main =
>>   beginnerProgram { model = "", view = view, update = update }
>>
>>
>> onContent tagger = 
>>   on "input" (JD.map tagger ("innerHTML" := JD.string))
>>
>> view model =
>>   div []
>> [ div [property "innerHTML" (JE.string model), onContent OnChange, 
>> contenteditable True][]
>> ]
>>
>>
>> type Msg = OnChange String 
>>
>>
>> update msg model =
>>   case (Debug.log "msg:" msg) of
>> OnChange str -> str
>>
>>
>>
>>
>>
>>
>> On Tue, Aug 30, 2016 at 12:03 PM, Vincent Jousse <vjo...@gmail.com> 
>> wrote:
>>
>>> Hello,
>>>
>>> I'm writing an application where the user needs to edit some HTML 
>>> content. When I first wrote this application in JS, I was using some 
>>> contenteditable fields to do so.
>>>
>>> How should I handle this with Elm? My problem is that if I set a div 
>>> with contenteditable=true in elm, and that the content of this div depends 
>>> on my model state, when an user edits the HTML, my model is now out of sync.
>>> Maybe getting the innerHTML field when the user is changing the content 
>>> of the div and set this to a field in my model? But how would I do to 
>>> convert this string back to some Html.div/Html.span/whatever code in Elm?
>>> The tricky part is that I need to handle events on spans that are in the 
>>> div with contenteditable=true.
>>>
>>> I tried to do it using Ports and Draft-js but the problem is that I now 
>>> have 2 states in my application: one in Elm and one in JS/React. Then, all 
>>> the beauty of "my application just depends on my Elm model state" is not 
>>> true anymore, as I know need to sync the 2 states…
>>>
>>> Not sure if I'm really clear, but thanks for reading this anyway ;-)
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elm-discuss...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> There is NO FATE, we are the creators.
>> blog: http://damoc.ro/
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon


That’s the way the virtual dom works, the view is rewritten on every loop

To be honest, I thought the exact opposite was the case - only bits that 
have changed are rewritten?

Meanwhile defaultValue a perfect solution

@Witold: I can see how your solution works in some cases where you have 
complete control of the model. But I have a recursive datastructure and 
can’t readily start adding extra fields into leaf values of my tree

Simon 

On Sunday, 22 January 2017 13:55:38 UTC+1, Bernardo wrote:

That's the way the virtual dom works, the view is rewritten on every loop. 
> You need to change line 49 to HA.defaultValue (toString model). 
>
> On Sunday, 22 January 2017 06:28:43 UTC-3, Simon wrote:
>>
>> Here is an example of the problem 
>> https://runelm.io/c/5nk
>>
>>
>>
>> On Sunday, 22 January 2017 10:22:34 UTC+1, Simon wrote:
>>>
>>> So my problem has evolved. I can see that onChange would work, but I am 
>>> also subscribing to KeyBoard.presses. As a result every keypress is 
>>> firing the update function even while onChange is waiting for a blur. 
>>>
>>> That shouldn’t be an issue I thought. If the key press does not change 
>>> the part of the model with the float in, then that part of the DOM would 
>>> not be rewritten, and indeed will remain constant until the ‘change’ event. 
>>> But that’s not the case. Even when I direct every keypress to NoOp (causing 
>>> update to return the model unchanged) the DOM is being rewritten and I’m 
>>> losing the edits in the input field.
>>>
>>> I believe a possible fix it to use Html.Keyed but, before I try that, 
>>> I’m wondering why the DOM is being rewritten and whether there are other 
>>> approaches I could take
>>>
>>> On Sunday, 22 January 2017 09:36:19 UTC+1, Simon wrote:
>>>
>>> Hi, 
>>>> your idea looked interesting until I tried it. https://runelm.io/c/y3g 
>>>>  
>>>> Try entering a number and then backspacing to delete it. I could not 
>>>> get rid of the first digit
>>>>
>>>>
>>>> I thought onChange would do it, but my early tests seem to suggest that 
>>>> it is firing just as often as onInput, which defeats the object
>>>>
>>>>
>>>> On Sunday, 22 January 2017 02:11:56 UTC+1, j weir wrote:
>>>>>
>>>>> Even simpler is to just use input [] [type_ "number"]  any reasons not 
>>>>> to?
>>>>>
>>>>> http://caniuse.com/#feat=input-number
>>>>>
>>>>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>>>>
>>>>> On Saturday, January 21, 2017 at 1:37:16 PM UTC-8, j weir wrote:
>>>>>>
>>>>>> You could also format the input so it is always a decimal.
>>>>>>
>>>>>> And instead of using Result.withDefault 0.0, revert to the existing 
>>>>>> value.
>>>>>> This way the input won't be destroyed if the user fat fingers a non 
>>>>>> numeral.
>>>>>>
>>>>>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Saturday, January 21, 2017 at 9:11:41 AM UTC-8, Rafał Cieślak 
>>>>>> wrote:
>>>>>>>
>>>>>>> I'd consider storing the whole string in the model and passing it to 
>>>>>>> value. This way you can capture whatever input the user types and 
>>>>>>> convert it to float only when you actually need to do something with 
>>>>>>> the 
>>>>>>> float.
>>>>>>>
>>>>>>> IMHO because the input tag allows you to type any kind of string, 
>>>>>>> you should treat the value that comes from its onBlur as a string. 
>>>>>>> You could set type_ to "number", but that would still not exclude 
>>>>>>> some invalid inputs from being provided.
>>>>>>>
>>>>>>> On Saturday, January 21, 2017 at 4:08:04 PM UTC+1, Simon wrote:
>>>>>>>>
>>>>>>>> I think it is not uncommon to collect dates and float values from 
>>>>>>>> users.
>>>>>>>>
>>>>>>>> update ...
>>>>>>>> NewValue v -> 
>>>>>>>> { model | floatvalue = String.toFloat v |> Result.withDefault 
>>>>>>>> 0.0 }
>>>>>>>>
>>>>>>>> floatInput : Float -> Html Msg 
>>>>>>>> floatInput v =
>>>>>>>> input 
>>>>>>>> [ onInput NewValue 
>>>>>>>> , value (toString v) 
>>>>>>>> ] []
>>>>>>>>
>>>>>>>> The problem with the above is that the moment you type the . 
>>>>>>>> toFloat fails and you get a 0 in your model. One way around it 
>>>>>>>> could be to delay processing of the value by using onBlur (below), but 
>>>>>>>> I 
>>>>>>>> was wondering how others handled this.
>>>>>>>>
>>>>>>>> floatInput_ : Float -> Html Msg 
>>>>>>>> floatInput_ v =
>>>>>>>> input 
>>>>>>>> [ onBlur NewValue 
>>>>>>>> , value (toString v) 
>>>>>>>> ] []
>>>>>>>>
>>>>>>>> ​
>>>>>>>>
>>>>>>> ​
>>>
>> ​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon
Here is an example of the problem 
https://runelm.io/c/5nk



On Sunday, 22 January 2017 10:22:34 UTC+1, Simon wrote:
>
> So my problem has evolved. I can see that onChange would work, but I am 
> also subscribing to KeyBoard.presses. As a result every keypress is 
> firing the update function even while onChange is waiting for a blur. 
>
> That shouldn’t be an issue I thought. If the key press does not change the 
> part of the model with the float in, then that part of the DOM would not be 
> rewritten, and indeed will remain constant until the ‘change’ event. But 
> that’s not the case. Even when I direct every keypress to NoOp (causing 
> update to return the model unchanged) the DOM is being rewritten and I’m 
> losing the edits in the input field.
>
> I believe a possible fix it to use Html.Keyed but, before I try that, I’m 
> wondering why the DOM is being rewritten and whether there are other 
> approaches I could take
>
> On Sunday, 22 January 2017 09:36:19 UTC+1, Simon wrote:
>
> Hi, 
>> your idea looked interesting until I tried it. https://runelm.io/c/y3g  
>> Try entering a number and then backspacing to delete it. I could not get 
>> rid of the first digit
>>
>>
>> I thought onChange would do it, but my early tests seem to suggest that 
>> it is firing just as often as onInput, which defeats the object
>>
>>
>> On Sunday, 22 January 2017 02:11:56 UTC+1, j weir wrote:
>>>
>>> Even simpler is to just use input [] [type_ "number"]  any reasons not 
>>> to?
>>>
>>> http://caniuse.com/#feat=input-number
>>>
>>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>>
>>> On Saturday, January 21, 2017 at 1:37:16 PM UTC-8, j weir wrote:
>>>>
>>>> You could also format the input so it is always a decimal.
>>>>
>>>> And instead of using Result.withDefault 0.0, revert to the existing 
>>>> value.
>>>> This way the input won't be destroyed if the user fat fingers a non 
>>>> numeral.
>>>>
>>>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>>>
>>>>
>>>>
>>>> On Saturday, January 21, 2017 at 9:11:41 AM UTC-8, Rafał Cieślak wrote:
>>>>>
>>>>> I'd consider storing the whole string in the model and passing it to 
>>>>> value. This way you can capture whatever input the user types and 
>>>>> convert it to float only when you actually need to do something with the 
>>>>> float.
>>>>>
>>>>> IMHO because the input tag allows you to type any kind of string, you 
>>>>> should treat the value that comes from its onBlur as a string. You 
>>>>> could set type_ to "number", but that would still not exclude some 
>>>>> invalid inputs from being provided.
>>>>>
>>>>> On Saturday, January 21, 2017 at 4:08:04 PM UTC+1, Simon wrote:
>>>>>>
>>>>>> I think it is not uncommon to collect dates and float values from 
>>>>>> users.
>>>>>>
>>>>>> update ...
>>>>>> NewValue v -> 
>>>>>> { model | floatvalue = String.toFloat v |> Result.withDefault 
>>>>>> 0.0 }
>>>>>>
>>>>>> floatInput : Float -> Html Msg 
>>>>>> floatInput v =
>>>>>> input 
>>>>>> [ onInput NewValue 
>>>>>> , value (toString v) 
>>>>>> ] []
>>>>>>
>>>>>> The problem with the above is that the moment you type the . toFloat 
>>>>>> fails and you get a 0 in your model. One way around it could be to 
>>>>>> delay processing of the value by using onBlur (below), but I was 
>>>>>> wondering 
>>>>>> how others handled this.
>>>>>>
>>>>>> floatInput_ : Float -> Html Msg 
>>>>>> floatInput_ v =
>>>>>> input 
>>>>>> [ onBlur NewValue 
>>>>>> , value (toString v) 
>>>>>> ] []
>>>>>>
>>>>>> ​
>>>>>>
>>>>> ​
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon


So my problem has evolved. I can see that onChange would work, but I am 
also subscribing to KeyBoard.presses. As a result every keypress is firing 
the update function even while onChange is waiting for a blur. 

That shouldn’t be an issue I thought. If the key press does not change the 
part of the model with the float in, then that part of the DOM would not be 
rewritten, and indeed will remain constant until the ‘change’ event. But 
that’s not the case. Even when I direct every keypress to NoOp (causing 
update to return the model unchanged) the DOM is being rewritten and I’m 
losing the edits in the input field.

I believe a possible fix it to use Html.Keyed but, before I try that, I’m 
wondering why the DOM is being rewritten and whether there are other 
approaches I could take

On Sunday, 22 January 2017 09:36:19 UTC+1, Simon wrote:

Hi, 
> your idea looked interesting until I tried it. https://runelm.io/c/y3g  
> Try entering a number and then backspacing to delete it. I could not get 
> rid of the first digit
>
>
> I thought onChange would do it, but my early tests seem to suggest that it 
> is firing just as often as onInput, which defeats the object
>
>
> On Sunday, 22 January 2017 02:11:56 UTC+1, j weir wrote:
>>
>> Even simpler is to just use input [] [type_ "number"]  any reasons not to?
>>
>> http://caniuse.com/#feat=input-number
>>
>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>
>> On Saturday, January 21, 2017 at 1:37:16 PM UTC-8, j weir wrote:
>>>
>>> You could also format the input so it is always a decimal.
>>>
>>> And instead of using Result.withDefault 0.0, revert to the existing 
>>> value.
>>> This way the input won't be destroyed if the user fat fingers a non 
>>> numeral.
>>>
>>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>>
>>>
>>>
>>> On Saturday, January 21, 2017 at 9:11:41 AM UTC-8, Rafał Cieślak wrote:
>>>>
>>>> I'd consider storing the whole string in the model and passing it to 
>>>> value. This way you can capture whatever input the user types and 
>>>> convert it to float only when you actually need to do something with the 
>>>> float.
>>>>
>>>> IMHO because the input tag allows you to type any kind of string, you 
>>>> should treat the value that comes from its onBlur as a string. You 
>>>> could set type_ to "number", but that would still not exclude some 
>>>> invalid inputs from being provided.
>>>>
>>>> On Saturday, January 21, 2017 at 4:08:04 PM UTC+1, Simon wrote:
>>>>>
>>>>> I think it is not uncommon to collect dates and float values from 
>>>>> users.
>>>>>
>>>>> update ...
>>>>> NewValue v -> 
>>>>> { model | floatvalue = String.toFloat v |> Result.withDefault 0.0 
>>>>> }
>>>>>
>>>>> floatInput : Float -> Html Msg 
>>>>> floatInput v =
>>>>> input 
>>>>> [ onInput NewValue 
>>>>> , value (toString v) 
>>>>> ] []
>>>>>
>>>>> The problem with the above is that the moment you type the . toFloat 
>>>>> fails and you get a 0 in your model. One way around it could be to 
>>>>> delay processing of the value by using onBlur (below), but I was 
>>>>> wondering 
>>>>> how others handled this.
>>>>>
>>>>> floatInput_ : Float -> Html Msg 
>>>>> floatInput_ v =
>>>>> input 
>>>>> [ onBlur NewValue 
>>>>> , value (toString v) 
>>>>> ] []
>>>>>
>>>>> ​
>>>>>
>>>> ​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Forms with Floats / Dates

2017-01-22 Thread Simon
Hi, 
your idea looked interesting until I tried it. https://runelm.io/c/y3g  
Try entering a number and then backspacing to delete it. I could not get 
rid of the first digit


I thought onChange would do it, but my early tests seem to suggest that it 
is firing just as often as onInput, which defeats the object


On Sunday, 22 January 2017 02:11:56 UTC+1, j weir wrote:
>
> Even simpler is to just use input [] [type_ "number"]  any reasons not to?
>
> http://caniuse.com/#feat=input-number
>
> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>
> On Saturday, January 21, 2017 at 1:37:16 PM UTC-8, j weir wrote:
>>
>> You could also format the input so it is always a decimal.
>>
>> And instead of using Result.withDefault 0.0, revert to the existing value.
>> This way the input won't be destroyed if the user fat fingers a non 
>> numeral.
>>
>> https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164
>>
>>
>>
>> On Saturday, January 21, 2017 at 9:11:41 AM UTC-8, Rafał Cieślak wrote:
>>>
>>> I'd consider storing the whole string in the model and passing it to 
>>> value. This way you can capture whatever input the user types and 
>>> convert it to float only when you actually need to do something with the 
>>> float.
>>>
>>> IMHO because the input tag allows you to type any kind of string, you 
>>> should treat the value that comes from its onBlur as a string. You 
>>> could set type_ to "number", but that would still not exclude some 
>>> invalid inputs from being provided.
>>>
>>> On Saturday, January 21, 2017 at 4:08:04 PM UTC+1, Simon wrote:
>>>>
>>>> I think it is not uncommon to collect dates and float values from users.
>>>>
>>>> update ...
>>>> NewValue v -> 
>>>> { model | floatvalue = String.toFloat v |> Result.withDefault 0.0 }
>>>>
>>>> floatInput : Float -> Html Msg 
>>>> floatInput v =
>>>> input 
>>>> [ onInput NewValue 
>>>> , value (toString v) 
>>>> ] []
>>>>
>>>> The problem with the above is that the moment you type the . toFloat 
>>>> fails and you get a 0 in your model. One way around it could be to 
>>>> delay processing of the value by using onBlur (below), but I was wondering 
>>>> how others handled this.
>>>>
>>>> floatInput_ : Float -> Html Msg 
>>>> floatInput_ v =
>>>> input 
>>>> [ onBlur NewValue 
>>>> , value (toString v) 
>>>> ] []
>>>>
>>>> ​
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Maintainers wanted

2017-01-21 Thread Simon
Despite the growth and strength of the Elm community, it is worth saying 
that your absence will really be missed Bogdan.

Simon


On Saturday, 21 January 2017 10:48:31 UTC+1, Bogdan Popa wrote:
>
> Ok, elm-community looks like a good place to move them to. Let's do that. 
> :)
>
> On Friday, January 20, 2017 at 8:42:29 PM UTC+2, Noah Hall wrote:
>>
>> Please move these to elm-community. I can help move them over. Reach 
>> on slack on #elm-community 
>>
>> On Fri, Jan 20, 2017 at 7:38 PM, Joey Eremondi <joey.e...@gmail.com> 
>> wrote: 
>> > Might these be candidates for migrating to elm-community? 
>> > 
>> > On Fri, Jan 20, 2017 at 2:29 AM, Bogdan Popa <popa.b...@gmail.com> 
>> wrote: 
>> >> 
>> >> Hi folks, 
>> >> 
>> >> Due to various reasons, I will no longer be focusing my attention on 
>> Elm 
>> >> for the foreseeable future. Unfortunately, this means that the 
>> libraries 
>> >> that I have created/have been maintaining so far will no longer be 
>> >> maintained by me. AFAICT, the following libraries are seeing a decent 
>> amount 
>> >> of use: 
>> >> 
>> >> * elm-combine 
>> >> * elm-datepicker 
>> >> * elm-route 
>> >> * elm-time 
>> >> 
>> >> It would be sad to see them die off and I would feel bad letting down 
>> any 
>> >> of their current users by not providing a path forward. If you depend 
>> on any 
>> >> of these and would like to step up and start maintaining one or more 
>> of 
>> >> them, please e-mail me directly. 
>> >> 
>> >> I had also been maintaining the Elm mode for Emacs for the past couple 
>> of 
>> >> years. I cannot give others commit access to that repository, but I'm 
>> sure 
>> >> @jcollard would happily do it if anyone wants to step up and maintain 
>> the 
>> >> project. 
>> >> 
>> >> Thanks! 
>> >> Bogdan 
>> >> 
>> >> -- 
>> >> You received this message because you are subscribed to the Google 
>> Groups 
>> >> "Elm Discuss" group. 
>> >> To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> >> email to elm-discuss...@googlegroups.com. 
>> >> For more options, visit https://groups.google.com/d/optout. 
>> > 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "Elm Discuss" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to elm-discuss...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread Simon
Correction 

toString (toFloat "5.") == "5"-i.e. the `.` gets stripped off so you 
can never actually add decimal values



On Saturday, 21 January 2017 16:08:04 UTC+1, Simon wrote:
>
> I think it is not uncommon to collect dates and float values from users.
>
> update ...
> NewValue v -> 
> { model | floatvalue = String.toFloat v |> Result.withDefault 0.0 }
>
> floatInput : Float -> Html Msg 
> floatInput v =
> input 
> [ onInput NewValue 
> , value (toString v) 
> ] []
>
> The problem with the above is that the moment you type the . toFloat 
> fails and you get a 0 in your model. One way around it could be to delay 
> processing of the value by using onBlur (below), but I was wondering how 
> others handled this.
>
> floatInput_ : Float -> Html Msg 
> floatInput_ v =
> input 
> [ onBlur NewValue 
> , value (toString v) 
> ] []
>
> ​
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Forms with Floats / Dates

2017-01-21 Thread Simon


I think it is not uncommon to collect dates and float values from users.

update ...
NewValue v -> 
{ model | floatvalue = String.toFloat v |> Result.withDefault 0.0 }

floatInput : Float -> Html Msg 
floatInput v =
input 
[ onInput NewValue 
, value (toString v) 
] []

The problem with the above is that the moment you type the . toFloat fails 
and you get a 0 in your model. One way around it could be to delay 
processing of the value by using onBlur (below), but I was wondering how 
others handled this.

floatInput_ : Float -> Html Msg 
floatInput_ v =
input 
[ onBlur NewValue 
, value (toString v) 
] []

​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Collecting use cases for File, ArrayBuffer and TypedArrays/DataViews

2017-01-11 Thread Simon
Hi all,
thought it might be worth updating this thread on my progress with S3, 
which I have now solved by adding one small hack to the Filereader 
<https://github.com/simonh1000/file-reader> library (github only because of 
the native code). I have documented this at 
https://simonh1000.github.io/2016/12/elm-s3-uploads/ 

Meanwhile, I have a new use to register. I was looking at MessagePack 
<http://msgpack.org/> and noted that Elm is not included in the long list 
of supported languages. I suspect that it currently could not be because of 
the lack of ArrayBuffer support?

Simon


On Wednesday, 24 August 2016 18:06:40 UTC+2, Erik Lott wrote:
>
> Our primary application allows photographers to upload hundreds/thousands 
> of images for portfolio display. image delivery, etc. I guess you could say 
> that our app is generally driven by image uploads. I would love to see this 
> functionality provided by Elm, rather than having to use ports...
>
> On Thursday, July 28, 2016 at 5:17:51 PM UTC-4, Daniel Bachler wrote:
>>
>> I'd love to see support for the File and ArrayBuffer Apis, and maybe 
>> TypedArrays/DataViews as well. IMHO they are an important piece of the Web 
>> Platform that is still missing in Elm.
>>
>> Evan suggested collecting concrete use cases to guide the design. I would 
>> like this thread to be the starting point of this effort. I would like to 
>> ask anyone who would also like this feature or who has substantial 
>> experience using either Api to add use cases or comment here so that we can 
>> try to define the user story for both apis. From there, we could decide 
>> what we would like to see supported and what, if anything, we don't need 
>> for now and suggest Elm Apis.
>>
>> I have two stories from a side project of mine. It is a slideshow editor 
>> that allows the user to select photos and audio files from the local 
>> system, uploads them to a web service, let's the user arrange and 
>> manipulate photos and music and then share the result with others. For 
>> this, I have two immediate use cases plus some more ideas:
>>
>> *Upload local files as binary blob to AWS S3*
>>
>> In my current, (hacky) version, I use the FileReader api (via 
>> simonH1000's filereader library) to read the content of a file into an 
>> ArrayBuffer, (represented as Json.Value in Elm) then use a modified version 
>> of elm-http to upload the content of the ArrayBuffer to an S3 storage 
>> bucket.
>>
>> *Download mp3 files, decode them and play them back via the AudioApi*
>>
>> Currently I do this with my modified http library to download the mp3 
>> file into an arraybuffer, then pass the resulting arraybuffer through a 
>> port to some native javascript that then uses the Audio Api to decode the 
>> mp3 file into a playable audiobuffer.
>>
>> *Parsing or otherwise processing local text files. *
>>
>> For another project I would be interested in reading and parsing 
>> Swagger/OpenAPI definition files and then providing a UI to compare rest 
>> apis. Since the processing will be done on simple Strings, this would only 
>> require FileReader support (specifically the readAsText method). This would 
>> already work with the FileReader library as is (though that one is not 
>> available on package.elm-lang.org because it contains native code and is 
>> not whitelisted).
>>
>> *TypedArrays and DataViews*
>>
>> I haven't worked with these yet, but I can anticipate some cases that 
>> would be interesting:
>>
>> *Parsing/manipulating of binary data via the ArrayBuffer api.*
>>
>> One case I personally would like to do with this, is to parse the Exif 
>> header of the jpeg files the user loaded from the local file system. My 
>> slideshow could then display metadata information without roundtripping to 
>> the server.
>>
>> *Create geometry for WebGL in the form of Vertex Buffers*
>>
>> *Generating sound/music by writing raw audio samples*
>>
>> These could then be played back via the Web audio apis.
>>
>>
>> Please add your own ideas to this thread. Once we have compiled a list of 
>> use cases, we can look at the JS Apis available under the Web Platform for 
>> Files, ArrayBuffers, Typed Arrays etc. and think how these could be exposed 
>> to Elm. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Weird bug where messages passed to the wrong 'component'

2017-01-02 Thread Simon
Impressive, even if it does not - at first sight - feel like it addresses 
my issue (as I have no lazy code)

On Saturday, 31 December 2016 21:21:09 UTC+1, Mark Hamburg wrote:
>
> Tracked down and reported against the virtual DOM but the short summary 
> for anyone else seeing routing problems — though possibly not the ones that 
> started this thread — is that DOM updates have trouble if you have a lazy 
> node that resolves to an Html.map node. Don't do that. At least until 
> there's a fix. If you want to be lazy, stick a div in or avoid the map by 
> pushing the tagger function further down.
>
> Mark
>
> On Dec 14, 2016, at 10:23 PM, Mark Hamburg <mhamb...@gmail.com 
> > wrote:
>
> I'm looking at a bug tonight that looks very much like a tagger got 
> dropped in processing messages coming up the HTML tree. This is with 
> various bits of Html.Keyed paranoia. I'm thinking more and more strongly 
> that there are bugs in the tagging logic in the virtual DOM. I guess I know 
> what I'm hunting for over Christmas...
>
> Mark
>
> On Wed, Dec 14, 2016 at 7:17 AM, Mark Hamburg <mhamb...@gmail.com 
> > wrote:
>
>> I was dealing with a case where a textfield from a login screen would 
>> blur after the screen had been removed and replaced by the main content. 
>> (Literally. I was looking at the new content.) The blur message would get 
>> tagged as headed for the content area which would then lead to a crash when 
>> the message wasn't understood.
>>
>> My fix was to put an Html.Keyed at the top of the tree to reflect what 
>> state the app was in. (And then in a bit of paranoia, I looked for other, 
>> similar places further down and added Html.Keyed protection there as well.)
>>
>> Mark
>>
>> On Dec 13, 2016, at 10:24 PM, Simon <hotb...@gmail.com > 
>> wrote:
>>
>> Thanks, I suspected that keyed would be part of the solution.
>> Any sense on whether I need to apply it only to the components being left 
>> (easy) with no need on those that the code is switching to (much leasy in 
>> my case)?
>>
>>
>> On Wednesday, 14 December 2016 03:55:29 UTC+1, Mark Hamburg wrote:
>>>
>>> I just dug into what I think is essentially the same bug. My guess was 
>>> that textfields were getting removed from the DOM and then firing their 
>>> blur events up through the event mapping chain — which had been updated to 
>>> match the new view tree structure. It's on my list to try to build a small 
>>> example of the bug after my team gets through its next milestone.
>>>
>>> In the meantime, I worked around this by making fairly aggressive use of 
>>> Html.Keyed to prevent pieces of the DOM from being reused.
>>>
>>> Mark
>>>
>>> On Dec 13, 2016, at 9:56 AM, Simon <hotb...@gmail.com> wrote:
>>>
>>> Sorry about using the C word!
>>>
>>> I had an error several months ago (0.16/0.17) where the wrong data would 
>>> be attached to message, causing all sorts of weirdness. It happened after a 
>>> successful logon and as the App tried to redirect to the main view. I have 
>>> a vague feeling that in the end all I needed to do was update 
>>> elm-lang/virtual-dom.
>>>
>>> Anyway, it has come back. It has something to do with when the browser 
>>> puts in login information for you. I can create the error by deleting the 
>>> auto-input and inserting my password and clicking enter to submit.
>>>
>>> Then what I see in my logs is this message
>>>
>>> `User.SwitchGroup: Blur "password"`
>>>
>>> Whereas SwitchGroup has type `String -> Msg` and `Blur "password"` are 
>>> artefacts of the elm-form library that was used in the Login component and 
>>> is not used in the User one.
>>>
>>> Does this remind anyone of something they have experienced, solved, and 
>>> remembered how they solved it?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elm-discuss...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Separate files for type declarations and code

2017-01-02 Thread Simon


I do it, but call it xx.Model.elm

On Sunday, 1 January 2017 00:37:41 UTC+1, Martin DeMello wrote:

I do the same thing in both ocaml and elm code. It's a pretty common 
> pattern.
>
> martin
>
> On Dec 31, 2016 3:29 PM, "Brian Marick"  
> wrote:
>
>> To avoid circular dependencies, I find myself putting type declarations 
>> in one file:
>>
>> > module Animals.Pages.Declare exposing (..)
>> >
>> > type PageChoice
>> >   = AllPage
>> >   | AddPage
>> >   | HelpPage
>>
>> … and related code in another:
>>
>> > module Animals.Pages.Define exposing
>> > ...
>> > toPageChangeCmd : PageChoice -> Cmd Msg
>> > toPageChangeCmd page =
>> >   let
>> >...
>> >   in
>> > Navigation.newUrl url
>>
>>
>> Is that typical, or am I missing something?
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
> ​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] What up with elm-mdl?

2016-12-22 Thread Simon
This is a brilliant post!

On Thursday, 22 December 2016 08:07:29 UTC+1, Peter Damoc wrote:
>
> On Wed, Dec 21, 2016 at 8:02 PM, Rex van der Spuy  > wrote:
>>
>> Can anyone explain what's going on?
>>
>
> I haven't been following elm-mdl lately but maybe I can provide some 
> historical context. 
>
> Reuse of UI is a topic that hasn't been solved in Elm. 
> This is why we don't have any official or recommended complex UI toolkit.
>
> The first real attempt at solving the issue was TEA (The Elm 
> Architecture). This was a pattern that was distilled by Evan into the 
> elm-architecture-tutorial. 
> That tutorial used to show how to define components and how to nest them. 
>
> Unfortunately, as soon as people started using the pattern for real work a 
> lot of discussions started to happen about messages flow (OutMsg) and some 
> people abused the pattern by splitting the code too much in terms of 
> components. 
>
> Another issue with fancy low level components (many small components that 
> are unavoidably stateful) is the amount of boilerplate needed and so, Søren 
> created elm-parts that addressed this and then implemented elm-mdl on top 
> of that. 
> Now, Evan moved away from recommending the nesting architecture and 
> advised against putting functions in Model & Msg. This put the 
> implementation of elm-mdl at odds with the official recommendation. 
>
> Polymer and webcomponents represent the latest attempt at exploring the UI 
> reuse issue in Elm. 
> This attempt is in its infancy. 
> Josh said that he will implement Firestorm using webcomponents and since 
> that kickstarter got funded we might see a real-world complex use of the 
> technology. 
>
> v1 of the WebComponents standard has been agreed upon by all major vendors 
> and I'm optimistic about its availability (I believe we'll see it available 
> next year in the evergreens)
> Others don't share my optimism and there is also the issue of mandated IE 
> support. 
>
> I guess we'll see what will happen next year. 
>
> In the end, I would like to say that the situation is so foggy that I 
> don't really have a solid recommendation. 
> elm-mdl looks like a dead-end while webcomponents is so brand new that we 
> still haven't figured out how to use it. 
>
> The best way forward now might be to use the 0.18 port of elm-mdl with the 
> flat hierarchy recommendations from the reuse part of the guide. Choose not 
> to block. 
> This might allow for an easy refactoring to a better technology. 
> (webcomponents) 
>
>
>
>
>
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Decoder headache.

2016-12-21 Thread Simon
Use 
andThen 
http://package.elm-lang.org/packages/elm-lang/core/5.0.0/Json-Decode#andThen


On Wednesday, 21 December 2016 13:38:14 UTC+1, Rupert Smith wrote:
>
> Struggling to figure this out, but it may be because I'm in an open plan 
> office and its just too noisy to concentrate...
>
> Suppose I have decoders for two records:
>
> type alias Circle =  { radius : Float }
> type alias Rectangle = { width: Float, height: Float }
>
> On the server side though, these are actually a class hierarchy, with
>
> Circle <: Shape
> Rectangle <: Shape
>
> Where <: means 'subtype of'.
>
> When serializing over json, a discriminator field is added, so the json 
> looks like:
>
> {
>   @type : "Circle",
>   radius : ...
> }
>
> {
>   @type : "Rectangle",
>   width : ...
> }
>
> I have decoders for circles and rectangles already defined:
>
> circleDecoder : Decoder Circle
> rectangleDecoder : Decoder Rectangle
>
> and am now trying to write the decoder for Shape:
>
> type Shape = 
>CircleAsShape Circle
>  | RectangleAsShape Rectangle
>
> shapeDecoder : Decoder Shape
> shapeDecoder = 
>   succeed (some function from '@type' to circle or rectangle decoder 
> mapped to shape decoder)
>   |: (field "@type" Decode.string)
>
> Feels about the right form for it. Exception this will return a Decoder 
> (Decoder Shape) instead of a Decoder Shape.
>
> Can someone explain how to do this?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] How to prevent input field values persisting in new views?

2016-12-21 Thread Simon
Yes, I have the same type of issue, but with the data attached to Blur 
messages attached arbitrarily to messages in new views. The way I solved it 
so far was to use Html.Keyed on the form page.

Simon

On Tuesday, 20 December 2016 22:33:26 UTC+1, Duane Johnson wrote:
>
>
> On Tue, Dec 20, 2016 at 2:03 PM, Wouter In t Velt <wouter@gmail.com 
> > wrote:
>
>>
>>- Is there a better way to *prevent* this from happening (rather than 
>>relying on our predictive instincts and applying Keyed when we suspect a 
>>leak)?
>>
>>
> I like that you're asking this question, because for me it sits at the 
> core of what I find attractive about Elm: the language gives us a break 
> from worrying about all of the ways things might break, and lets us focus 
> on the business logic of an app.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Which problems did you solve using the Elm debugger?

2016-12-20 Thread Simon
It would be much more useful for me if you could see the whole message 

On Monday, 19 December 2016 15:51:46 UTC+1, Wouter In t Velt wrote:
>
> Op maandag 19 december 2016 15:06:28 UTC+1 schreef Jeff Horemans:
>>
>> Can anyone give (concrete) examples wherein the debugger proved to be 
>> useful, even crucial, in resolving the problem or bug?
>>
>
> The debugger for me is very useful to find out if Msg fired and in which 
> order.
> When interacting with the DOM elements through custom event handlers (e.g. 
> on "dragleave"), I need to find out if the event fired at all, and in which 
> order.
>
> Especially when processing output from side effects (UI events in my 
> case), the debugger comes in handy.
> Wish I could expand the message itself, but even in current version, 
> seeing which messages fired and in which order is useful.
>
> Going back through the messages that did fire, and then look up if my 
> model ended up correctly is quite useful.
> (Way more friendly than Debug.log everything)
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Stance on native APIs for 0.18?

2016-12-16 Thread Simon
> * A "foreign" value type that could capture a reference coming from 
JavaScript to be handed back in other calls.

We already have that with Json.Encode.Value, and it can be passed to from 
javascript: see this example for Google maps 
<http://simonh1000.github.io/2016/12/elm-ports-google-maps/>, which I 
copied from how Evan built websockets

Simon


On Thursday, 8 December 2016 19:28:22 UTC+1, Mark Hamburg wrote:
>
> I was talking about this further with my coworkers and we more or less 
> agreed that the key things that could help with Elm's interface to 
> JavaScript were:
>
> * Task ports. Tasks are a building block in a way that commands are not. 
> Forcing all external interactions to be asynchronous makes it more clear 
> that one is stepping outside and code could fail.
>
> * A "foreign" value type that could capture a reference coming from 
> JavaScript to be handed back in other calls. For example, though not a 
> great JavaScript example, this could be a database connection. All 
> operations on the database would occur via tasks. We just need an easy way 
> for Elm to hold the handle to the database connection. This functionality 
> would be better if the foreign types could be distinguished within Elm in 
> their declaration — e.g.
>
> port type DBConnection
>
> ("port" reads wrong but I was avoiding introducing a new keyword.)
>
> That said, one could also just use Foreign as a base type and use Elm code 
> wrap it in more meaning for the type checker:
>
> type DBConnection = DBConnection Foreign
>
> This, however, probably makes it harder to use the types safely in the 
> task APIs.
>
> Would those two features address everything needed? No. In particular, 
> port wireup inhibits creating libraries. But it would make it much more 
> straightforward for any individual project to build interfaces to 
> JavaScript-based functionality.
>
> Mark
>
> On Thu, Dec 8, 2016 at 9:27 AM Vojtěch Král <vojtechkr...@gmail.com 
> > wrote:
>
>>
>> Dne úterý 6. prosince 2016 23:14:06 UTC+1 Rupert Smith napsal(a):
>>
>>> The thing about ports for something like this is it feels a bit 
>>> unnatural to invoke the port resulting in a Cmd. Then you'll need a 
>>> subscription port to get the result back in, and have that pass it to your 
>>> update function from where you can take it and place it in the model. That 
>>> doesn't feel like a good way to call a function : String -> Ast.
>>>
>>> I'd say the best solution is to implemented your parser in pure Elm. But 
>>> if that is too much work, just hack together a native module that calls out 
>>> to commonmark.js. You won't be able to publish your native module to elm 
>>> packages, but that's ok, perhaps no-one else really wants your markdown 
>>> with embedded SQL anyway, and if they do there is always 
>>> elm-github-install. Some time down the road when you really need to share 
>>> this amazing library, redo it in pure Elm. 
>>>
>>
>> This resonates with me very much. This is _exactly_ the reason why I made 
>> The Elm Alienation post on Reddit: 
>> https://www.reddit.com/r/elm/comments/5g3540/the_elm_alienation/
>>
>> I also wanted to ask here about the status of the Native API but I'm 
>> seeing you guys already inquired.
>>
>> Forcing people to rewrite everything in Elm is a terrible idea.
>>
>>
>> Dne středa 7. prosince 2016 17:18:37 UTC+1 Mark Hamburg napsal(a):
>>
>>> Would
>>>
>>> it help if there were a standard mechanism to invoke JavaScript code as
>>>
>>> a task (or equivalently to make JavaScript code available as a task)?
>>>
>>
>> Yes! Very much! If this happened, I'd definitely revisit the decision to 
>> leave Elm.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>>
>>
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>>
>>
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>>
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How to use Navigation library

2016-12-15 Thread Simon


Basically you have two ways to move around the app (not to use the word 
‘navigate’): 

   - buttons, which will only change the Url if you use Navigation.newUrl 
   after their click Message returns 
   - anchor links that will change the url, but to which you have add a 
   click handler 

on "click" {preventDefault = True, ...} ...

to prevent the page being totally reloaded.

Whenever the url is changed, Navigation will create a new message that you 
can either ignore (if you are updating your model in the original event 
handler), or you wait till the Navigation message hits and take action at 
that stage. Notionally the latter is more elegant, but I don’t think it 
makes much practical difference.

On Thursday, 15 December 2016 18:31:31 UTC+1, ssciantarelli wrote:

Simon (especially),
>
> I'm trying to figure out the exact same thing you were hung up on, can you 
> (or anyone else that knows) please inform on what changes you made to get 
> it working? I've tried doing exactly what you demonstrated in your example 
> and run into the same issues:
> https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2.
>
> I've also tried using the elm-route-url package, but it seems every time 
> delta2url is called "previous" and "current" are always the same, and never 
> represent what was just clicked. Here's what I tried on that front:
> https://gist.github.com/ssciantarelli/0cba172048f3c9c28754ba4d0ac5a6b1
>
> Finally, I have a StackOverflow post that ultimately explains where I'm 
> going with this if anyone cares to comment/answer over there:
>
> http://stackoverflow.com/questions/41169224/is-it-possible-to-drive-elm-app-with-existing-navigation-constructed-outside-of
>
> Thanks all.
>
> On Sunday, November 27, 2016 at 4:31:27 AM UTC-6, Simon wrote:
>>
>> Erik,
>> thanks so much. I now understand everything. What had confused me was the 
>> example in the Navigation library. Because that uses hash-routing , it can 
>> work with anchors and not need to create Messages and use preventdefault. I 
>> had inferred too much form that about how to work with ordinary links. It 
>> tuend out then that I only needed to make modest changes to my App to make 
>> routing helpful, rather than a massive source of extra, unused messages!
>>
>> Simon
>>
>> On Sunday, 27 November 2016 02:00:08 UTC+1, Erik Lott wrote:
>>>
>>> that should say :
>>> Simon, I'm just glancing at this code, but this page *shouldn't* 
>>>  perform page refreshes at all. It should only fire UrlChange events 
>>> without reload the browser. Am I missing something?
>>>
>>> On Saturday, November 26, 2016 at 5:59:56 PM UTC-5, Erik Lott wrote:
>>>>
>>>> The aim is to get the navigation history ticking along properly without 
>>>>> page refreshes.
>>>>
>>>>
>>>> Simon, I'm just glancing at this code, but this page should perform 
>>>> page refreshes at all. It should only fire UrlChange events without reload 
>>>> the browser. Am I missing something?
>>>>
>>>> On Saturday, November 26, 2016 at 10:54:53 AM UTC-5, Simon wrote:
>>>>>
>>>>> Here is some code to make things more concrete
>>>>> https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2
>>>>>
>>>>> It is based on the example from the Navigation library, but with the 
>>>>> links changed from # to (I think they are called) HTML5 links.
>>>>>
>>>>> I added an onClick handler to provide a preventDefault as otherwise 
>>>>> the links 404, but with this handler the links don’t navigate instead
>>>>>
>>>>> The aim is to get the navigation history ticking along properly 
>>>>> without page refreshes.
>>>>>
>>>>> I know its possible as I’ve seen it in other routers
>>>>>
>>>>> Simon
>>>>>
>>>>> On Saturday, 26 November 2016 13:44:20 UTC+1, Wouter In t Velt wrote:
>>>>>
>>>>> Thank you for the explanation Erik! With the upgrade to 0.18 and the 
>>>>>> changes in navigation, I was wondering which route (pun intended) to 
>>>>>> follow 
>>>>>> with the upgrade. Not sure I follow completely though.
>>>>>>
>>>>>> In option 1, could you deal with redirect-like scenario's inside the 
>>>>>> SPA?
>>>>>> Like
>>>>>>
>>>>>>1. user is on the "/apples" page, showing all available apples.
>>>>>>2. user types "/apples/234"  in the url-bar
>>>>>>3. there happens to be no such apple
>>>>>>4. I want the user to stay on the "/apples" page, and get a 
>>>>>>message like "this apple is forbidden fruit"
>>>>>>5. at this point, I would want the url-bar to also say "/apples"
>>>>>>
>>>>>> Can this work with option 1? Or is this only possible with option 2?
>>>>>>
>>>>> ​
>>>>>
>>>> ​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Weird bug where messages passed to the wrong 'component'

2016-12-13 Thread Simon
Thanks, I suspected that keyed would be part of the solution.
Any sense on whether I need to apply it only to the components being left 
(easy) with no need on those that the code is switching to (much leasy in 
my case)?


On Wednesday, 14 December 2016 03:55:29 UTC+1, Mark Hamburg wrote:
>
> I just dug into what I think is essentially the same bug. My guess was 
> that textfields were getting removed from the DOM and then firing their 
> blur events up through the event mapping chain — which had been updated to 
> match the new view tree structure. It's on my list to try to build a small 
> example of the bug after my team gets through its next milestone.
>
> In the meantime, I worked around this by making fairly aggressive use of 
> Html.Keyed to prevent pieces of the DOM from being reused.
>
> Mark
>
> On Dec 13, 2016, at 9:56 AM, Simon <hotb...@gmail.com > 
> wrote:
>
> Sorry about using the C word!
>
> I had an error several months ago (0.16/0.17) where the wrong data would 
> be attached to message, causing all sorts of weirdness. It happened after a 
> successful logon and as the App tried to redirect to the main view. I have 
> a vague feeling that in the end all I needed to do was update 
> elm-lang/virtual-dom.
>
> Anyway, it has come back. It has something to do with when the browser 
> puts in login information for you. I can create the error by deleting the 
> auto-input and inserting my password and clicking enter to submit.
>
> Then what I see in my logs is this message
>
> `User.SwitchGroup: Blur "password"`
>
> Whereas SwitchGroup has type `String -> Msg` and `Blur "password"` are 
> artefacts of the elm-form library that was used in the Login component and 
> is not used in the User one.
>
> Does this remind anyone of something they have experienced, solved, and 
> remembered how they solved it?
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to elm-discuss...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Weird bug where messages passed to the wrong 'component'

2016-12-13 Thread Simon
Sorry about using the C word!

I had an error several months ago (0.16/0.17) where the wrong data would be 
attached to message, causing all sorts of weirdness. It happened after a 
successful logon and as the App tried to redirect to the main view. I have 
a vague feeling that in the end all I needed to do was update 
elm-lang/virtual-dom.

Anyway, it has come back. It has something to do with when the browser puts 
in login information for you. I can create the error by deleting the 
auto-input and inserting my password and clicking enter to submit.

Then what I see in my logs is this message

`User.SwitchGroup: Blur "password"`

Whereas SwitchGroup has type `String -> Msg` and `Blur "password"` are 
artefacts of the elm-form library that was used in the Login component and 
is not used in the User one.

Does this remind anyone of something they have experienced, solved, and 
remembered how they solved it?

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Resizeing the events panel in the debugger

2016-12-07 Thread Simon
https://github.com/elm-lang/virtual-dom/issues/49

On Wednesday, 7 December 2016 13:39:40 UTC+1, Zachary Kessin wrote:
>
> Is it possible to resize the events panel (On the left side) of the 
> debugger, I have some events with longer names it would be nice to see a 
> bit more of the names
>
> Zach
>
> -- 
> Zach Kessin
> SquareTarget 
> Twitter: @zkessin 
> Skype: zachkessin
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Stance on native APIs for 0.18?

2016-12-07 Thread Simon
Are there additional restrictions on using native code? I installed a 
library with native code using elm-github-install. As far as I can see 
`"native-modules": true` is set in the library but it still cannot find the 
native code, whereas the native code from the http library that is also in 
the project is read.

Simon

On Tuesday, 6 December 2016 23:14:06 UTC+1, Rupert Smith wrote:
>
> On Tuesday, December 6, 2016 at 7:32:49 PM UTC, Rupert Smith wrote:
>>
>> On Tuesday, December 6, 2016 at 5:18:04 PM UTC, Wil C wrote:
>>>
>>> So now, either I write a ports for commonmark.js, or I write it as a 
>>> native module. I asked about it here 
>>> <https://groups.google.com/forum/#!topic/elm-discuss/Kd53qnKY-io> with 
>>> no answers. 
>>>
>>
>> I think if you write it as ports or native, you'll still need to map the 
>> AST between javascript and Elm. As a native module that could be done with 
>> a Decoder or by constructing the Elm AST in native code with Javascript. 
>> Perhaps Decoders are not so bad?
>>
>> I don't think a parser is a side-effect. A parser is a pure function from 
>> String -> Ast, with no side effects.
>>
>
> The thing about ports for something like this is it feels a bit unnatural 
> to invoke the port resulting in a Cmd. Then you'll need a subscription port 
> to get the result back in, and have that pass it to your update function 
> from where you can take it and place it in the model. That doesn't feel 
> like a good way to call a function : String -> Ast.
>
> I'd say the best solution is to implemented your parser in pure Elm. But 
> if that is too much work, just hack together a native module that calls out 
> to commonmark.js. You won't be able to publish your native module to elm 
> packages, but that's ok, perhaps no-one else really wants your markdown 
> with embedded SQL anyway, and if they do there is always 
> elm-github-install. Some time down the road when you really need to share 
> this amazing library, redo it in pure Elm. 
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Integrating Elm with Web Components / Polymer

2016-12-04 Thread Simon
Is the video available now?

On Friday, 4 November 2016 02:36:52 UTC+1, Richard Feldman wrote:
>
> Yes and yes! I'll post when the video is up.
>
> On Thu, Nov 3, 2016 at 3:45 PM, Peter Damoc  > wrote:
>
>> This is pretty awesome. 
>>
>> Have you given the talk in Vienna? 
>> Is this part of that talk? :) 
>>
>>
>>
>> On Thu, Nov 3, 2016 at 6:54 PM, Richard Feldman > > wrote:
>>
>>> FYI I got Google Maps working based on Fred's calendar repo: 
>>> https://github.com/rtfeldman/elm-google-maps
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elm-discuss...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> There is NO FATE, we are the creators.
>> blog: http://damoc.ro/
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Elm Discuss" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/elm-discuss/8Q2xwRh6UYc/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: What's the best way to chain updates?

2016-12-02 Thread Simon


I think you want to do something like:

 { model | -- update the record properties -- }
|> update SecondThing 
|> update ThirdThing 
|> update FourthThing

On Friday, 2 December 2016 17:56:37 UTC+1, Rex van der Spuy wrote:

Hi Everyone,
>
> Usually when I want a series of updates to chain in sequence, I'll write 
> some code like this:
>
> FirstThing ->
>   let 
> newModel = { model | -- update the record properties -- }
>   in
> update SecondThing newModel
>
> SecondThing ->
>   let 
> newModel = { model | -- update the record properties -- }
>   in
> update ThirdThing newModel
>
> ThirdThing ->
>   let 
> newModel = { model | -- update the record properties -- }
>   in
> update LastThing newModel
>
> LastThing ->
>   let 
> newModel = { model | -- update the record properties -- }
>   in
> newModel ! [ ]
>
>
> But... isn't this similar to using a GOTO statement in BASIC?
> (Hey, I love BASIC, but... !)
> I've found that when I have a few of these chained in sequence, spaghetti 
> code is the guaranteed result.
>
> Is there someway to manage this sequencing in some kind of centralized way?
> For example, something like:
>
> SequenceOfSteps ->
>   FirstThing 
>   SecondThing
>   ThirdThing
>   LastThing
>
> It would be nice to do this so that I can selectively insert or remove 
> steps while testing my application.
>
> Is this possible?
> Any advice or opinions?
>
> ​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Instaslling Elm 0.17 and Elm 0.18 at the same time.

2016-11-29 Thread Simon
The easy way is to install elm locally to your project - `npm i elm@0.17` - 
and then I think elm-make will find it there (and if not, will default to 
the system installed version).

(Got the idea from Noah a couple of weeks ago)

On Tuesday, 29 November 2016 14:54:06 UTC+1, Rupert Smith wrote:
>
> I've been trying to follow these instructions:
>
> http://www.lambdacat.com/how-to-setup-local-development-for-elm/
>
> but getting some errors when trying to build from source.
>
> Is there an easier way? I don't want to blat my exising 0.17 with 0.18 
> right away, would rather keep it around until I have finished upgrading.
>
> Perhaps just create a vm or docker container and install elm 0.18 inside 
> that?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How to use Navigation library

2016-11-27 Thread Simon
Erik,
thanks so much. I now understand everything. What had confused me was the 
example in the Navigation library. Because that uses hash-routing , it can 
work with anchors and not need to create Messages and use preventdefault. I 
had inferred too much form that about how to work with ordinary links. It 
tuend out then that I only needed to make modest changes to my App to make 
routing helpful, rather than a massive source of extra, unused messages!

Simon

On Sunday, 27 November 2016 02:00:08 UTC+1, Erik Lott wrote:
>
> that should say :
> Simon, I'm just glancing at this code, but this page *shouldn't*  perform 
> page refreshes at all. It should only fire UrlChange events without reload 
> the browser. Am I missing something?
>
> On Saturday, November 26, 2016 at 5:59:56 PM UTC-5, Erik Lott wrote:
>>
>> The aim is to get the navigation history ticking along properly without 
>>> page refreshes.
>>
>>
>> Simon, I'm just glancing at this code, but this page should perform page 
>> refreshes at all. It should only fire UrlChange events without reload the 
>> browser. Am I missing something?
>>
>> On Saturday, November 26, 2016 at 10:54:53 AM UTC-5, Simon wrote:
>>>
>>> Here is some code to make things more concrete
>>> https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2
>>>
>>> It is based on the example from the Navigation library, but with the 
>>> links changed from # to (I think they are called) HTML5 links.
>>>
>>> I added an onClick handler to provide a preventDefault as otherwise the 
>>> links 404, but with this handler the links don’t navigate instead
>>>
>>> The aim is to get the navigation history ticking along properly without 
>>> page refreshes.
>>>
>>> I know its possible as I’ve seen it in other routers
>>>
>>> Simon
>>>
>>> On Saturday, 26 November 2016 13:44:20 UTC+1, Wouter In t Velt wrote:
>>>
>>> Thank you for the explanation Erik! With the upgrade to 0.18 and the 
>>>> changes in navigation, I was wondering which route (pun intended) to 
>>>> follow 
>>>> with the upgrade. Not sure I follow completely though.
>>>>
>>>> In option 1, could you deal with redirect-like scenario's inside the 
>>>> SPA?
>>>> Like
>>>>
>>>>1. user is on the "/apples" page, showing all available apples.
>>>>2. user types "/apples/234"  in the url-bar
>>>>3. there happens to be no such apple
>>>>4. I want the user to stay on the "/apples" page, and get a message 
>>>>like "this apple is forbidden fruit"
>>>>5. at this point, I would want the url-bar to also say "/apples"
>>>>
>>>> Can this work with option 1? Or is this only possible with option 2?
>>>>
>>> ​
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How to use Navigation library

2016-11-26 Thread Simon


Here is some code to make things more concrete
https://gist.github.com/simonh1000/9368f9dbd7f93646207ec27fdf3662a2

It is based on the example from the Navigation library, but with the links 
changed from # to (I think they are called) HTML5 links.

I added an onClick handler to provide a preventDefault as otherwise the 
links 404, but with this handler the links don’t navigate instead

The aim is to get the navigation history ticking along properly without 
page refreshes.

I know its possible as I’ve seen it in other routers

Simon

On Saturday, 26 November 2016 13:44:20 UTC+1, Wouter In t Velt wrote:

Thank you for the explanation Erik! With the upgrade to 0.18 and the 
> changes in navigation, I was wondering which route (pun intended) to follow 
> with the upgrade. Not sure I follow completely though.
>
> In option 1, could you deal with redirect-like scenario's inside the SPA?
> Like
>
>1. user is on the "/apples" page, showing all available apples.
>2. user types "/apples/234"  in the url-bar
>3. there happens to be no such apple
>4. I want the user to stay on the "/apples" page, and get a message 
>like "this apple is forbidden fruit"
>5. at this point, I would want the url-bar to also say "/apples"
>
> Can this work with option 1? Or is this only possible with option 2?
>
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How to use Navigation library

2016-11-25 Thread Simon
With option 1 how do you stop the page reloading on each click on an anchor?

Another Con of option 1 might be that it can't cover so many scenarios. 
Suppose that you have a form, click submit and then - on successful 
completion of some persistence stage - you want to redirect to another 
page. (Or is that possible by combining some kind of redirect command with 
the confirmation from the server, and again here how would you prevent page 
reloading?)

On Friday, 25 November 2016 23:29:49 UTC+1, Erik Lott wrote:
>
>  Is there any reason to favour one over the other, otherwise I'm likely to 
>> go with 2.
>
>
> Yeah, I would say stick with option 1. Our large SPA in elm has used 
> option 2 for the past 5 months, and we've recently swapped over to option 
> 1. Here are some pros & cons:
>
> Option 1:
> Pros
>
>- Embraces the browser by creating real clickable links. I can CMD + 
>click on a link and open it in a new tab, I can CTRL + click and open it 
> in 
>a new window.
>- Easier to implement in Elm (not necessarily better, just easier) 
>compared to option 2
>- Easier to maintain to understand. 
>- Routing state does not need to be stored in the root model. This is 
>tough to explain. Using option 1, If someone navigates to "/apples/234" in 
>your elm app, your app would parse that url and generate a Msg like 
>"AppleRoute 234", send the msg to update func, fetch the "apple" resource 
>id=234 from the backend server via http, and use that data to display the 
>"ApplePage". Done. Although we needed id "234" to load the apple data, 
>there is no reason for us to store that id in the root model of our 
>application - After it's been used to load the page, it can be discarded. 
>Not so, however, for option 2. You're forced to store that ID in your root 
>model so that you can derive the address bar url from it.  
>
> Cons
>
>- Even though it is easier to maintain, read, and write (hahaha) I 
>strongly dislike one aspect of option 1. Why should I use the browser to 
>pass messages around my app (click an html link > the browser updates the 
>address bar > elm root receives url change msg) when elm can pass messages 
>internally  just fine. Arg...
>
>
> Option 2
> Cons
>
>- Lots of msg translating and indirection - There will be a healthy 
>amount of upward messaging from child to parent (notify root that a 
>navigation link in the child was clicked). I wouldn't recommend this to 
>anyone just getting started with elm, but if you already have experience 
>with elm, go for it.
>- You need to store routing state in the root model, specifically for 
>the address bar representation.
>- Links in your html view will not be real href links, so you lose 
>some functionality mentioned in the option1 pros.
>
> Pro
>
>- All aspects of the application are driven by elm. The internal 
>messaging is done in elm. Address bar changes are driven by Elm. You could 
>    easily swap this app to a different platform (anything that is not the 
>browser), make a few changes to your view layer, and blammo - the app 
> would 
>run.
>
>
>
>
>
>
> On Friday, November 25, 2016 at 11:22:01 AM UTC-5, Simon wrote:
>>
>> Erik,
>> that makes such a lot of sense. Thanks for spelling it out. Is there any 
>> reason to favour one over the other, otherwise I'm likely to go with 2.
>> Simon
>>
>> On Friday, 25 November 2016 16:52:20 UTC+1, Erik Lott wrote:
>>>
>>> When you're creating an SPA in elm, you'll generally need to choose one 
>>> of two navigation styles:
>>>
>>> *1. Allow the address bar to drive your model*
>>> The standard Navigation package provides this type of functionality. 
>>> Your model will respond to changes in the address bar, and your views will 
>>> (generally) use view links (a tags) to change the address bar. You may have 
>>> a few sprinkles of manual url changing commands throughout the app for 
>>> redirection, but for the most part, the majority of url changes are caused 
>>> by users clicking on html links in your view.
>>>
>>> The changes flow like this : View --> Address Bar --> Model --> View 
>>>
>>> *2. Allow your model to drive the address bar*
>>> In this case, the address bar is simply a reflection of the current 
>>> state of your model. There is no need to update the address bar manually, 
>>> because it will keep itself in sync with your model. Try using a routing 
>>> package like Elm Rou

[elm-discuss] Re: Using Navigation - is Events.onWithOptions required?

2016-11-25 Thread Simon
You should 
read https://groups.google.com/forum/#!topic/elm-discuss/KacB1VqkVJg too
There are clearly 2 ways to achieve the same goal. Brian's is the one you 
get to if you build up from just the Basics library, while you might go 
Wouter's way if you bake in the Navigation library from the outset.




On Saturday, 26 November 2016 01:08:01 UTC+1, OvermindDL1 wrote:
>
> I actually prefer to have anchor tags around the document but have a top 
> level catch that stops page movements to url's I whitelist and instead just 
> redirects navigation (which then updates other parts of the app), seems the 
> most simple, but it is definitely not wrapped up in an easy way in elm yet 
> (and mine is in javascript...).
>
> On Wednesday, November 23, 2016 at 4:41:02 PM UTC-7, Wouter In t Velt 
> wrote:
>>
>> Op woensdag 23 november 2016 23:52:54 UTC+1 schreef Brian Marick:
>>>
>>> So I suspect I’m doing something wrong. Am I?
>>>
>>
>> Not wrong, I guess, but it is kind of a peculiar setup.
>>
>> I also use elm-lang/navigation, and never ran into this issue.
>> After checking my code:
>>
>>- Either I use an `a [ href "#/path/location ]` to let the url-parser 
>>navigate when the user clicks the link.
>>- Or I use `button [ onClick (NavigateTo NewLocation) ]` to go to the 
>>update function.
>>
>> (urlUpdate and update are wired so that navigation instructions can come 
>> in through either function).
>>
>> So it seems kind of double to use both the href and the onClick on the 
>> same element to do navigation.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How to use Navigation library

2016-11-25 Thread Simon
Erik,
that makes such a lot of sense. Thanks for spelling it out. Is there any 
reason to favour one over the other, otherwise I'm likely to go with 2.
Simon

On Friday, 25 November 2016 16:52:20 UTC+1, Erik Lott wrote:
>
> When you're creating an SPA in elm, you'll generally need to choose one of 
> two navigation styles:
>
> *1. Allow the address bar to drive your model*
> The standard Navigation package provides this type of functionality. Your 
> model will respond to changes in the address bar, and your views will 
> (generally) use view links (a tags) to change the address bar. You may have 
> a few sprinkles of manual url changing commands throughout the app for 
> redirection, but for the most part, the majority of url changes are caused 
> by users clicking on html links in your view.
>
> The changes flow like this : View --> Address Bar --> Model --> View 
>
> *2. Allow your model to drive the address bar*
> In this case, the address bar is simply a reflection of the current state 
> of your model. There is no need to update the address bar manually, because 
> it will keep itself in sync with your model. Try using a routing package 
> like Elm Route Url (
> http://package.elm-lang.org/packages/rgrempel/elm-route-url/latest). Take 
> a moment and read the package readme. It clearly explains the difference 
> between the 2 styles of routing. If you use this style of navigation, 
> you'll need to build your application in such a way that the navigation is 
> kept within elm and does not require the address bar. For example, rather 
> than including a tag links in your html view to change the url directly, 
> your a-tags or buttons will trigger Msg's that will update your model, and 
> then the address bar will respond to the model change.
>
>
>
>
>
>
>
> On Friday, November 25, 2016 at 4:32:50 AM UTC-5, Simon wrote:
>>
>> OK, I just don’t quite understand, even while I have working code!
>>
>> I have an app where, as the model changes (in particular the value 
>> representing the ‘page’ of my single page app), the Url is updated with 
>> this task
>>
>> Navigation.newUrl (toUrl model)
>>
>> But as the Url changes, I get a new message from Navigation because of:
>>
>> main =
>> Navigation.programWithFlags
>> (Routing.urlParser RouteTo)
>> { init = initWithFlags
>> , update = Routing.update
>> , view = view
>> , subscriptions = subscriptions
>> }
>>
>> When first loading the app, this message is useful and I can use it to 
>> direct to the appropriate opening page. But thereafter this message is 
>> redundant - I already made all the model changes I wanted before and that 
>> caused the Url update. Without some care I even get a loop of each Routing 
>> message causing the 
>>
>> *I suspect I am missing something rather important, but am not sure what?*
>>
>> One option would be to use anchor tags to cause the switch pages, and 
>> only do model changes when I get a RouteTo message, but even then I have 
>> some url changes resulting from the clicking on an element within a page, 
>> and I don’t think that is a place for anchors. (As I use html urls, rather 
>> than # ones I also have to be careful not to let the page get reloaded)
>> ​
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] How to use Navigation library

2016-11-25 Thread Simon


OK, I just don’t quite understand, even while I have working code!

I have an app where, as the model changes (in particular the value 
representing the ‘page’ of my single page app), the Url is updated with 
this task

Navigation.newUrl (toUrl model)

But as the Url changes, I get a new message from Navigation because of:

main =
Navigation.programWithFlags
(Routing.urlParser RouteTo)
{ init = initWithFlags
, update = Routing.update
, view = view
, subscriptions = subscriptions
}

When first loading the app, this message is useful and I can use it to 
direct to the appropriate opening page. But thereafter this message is 
redundant - I already made all the model changes I wanted before and that 
caused the Url update. Without some care I even get a loop of each Routing 
message causing the 

*I suspect I am missing something rather important, but am not sure what?*

One option would be to use anchor tags to cause the switch pages, and only 
do model changes when I get a RouteTo message, but even then I have some 
url changes resulting from the clicking on an element within a page, and I 
don’t think that is a place for anchors. (As I use html urls, rather than # 
ones I also have to be careful not to let the page get reloaded)
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] How to use Routing

2016-11-25 Thread Simon
OK, I just don't quite understand, even while I have working code!

I have an app where, as the model changes (in particular the value 
representing the 'page' of my single page app), the Url is updated with 
this task

```
Navigation.newUrl (toUrl model)
```

But as the Url changes, I get a new message from Navigation because of:
```
main =
Navigation.programWithFlags
(Routing.urlParser RouteTo)
{ init = initWithFlags
, update = Routing.update
, view = view
, subscriptions = subscriptions
}

```

When first loading the app, this message is useful and I can use it to 
direct to the appropriate opening page. But thereafter this message is 
redundant - I already made all the model changes I wanted before and that 
caused the Url update. Without some care I even get a loop of each Routing 
message causing the 

*I suspect I am missing something rather important, but am not sure what?*

One option would be to use anchor tags to cause the switch pages, and only 
do model changes when I get a `RouteTo` message, but even then I have some 
url changes resulting from the clicking on an element within a page, and I 
don't think that is a place for anchors. (As I use html urls, rather than 
`#` ones I also have to be careful not to let the page get reloaded)

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Dynamic Unsubscribing to subscriptions?

2016-11-23 Thread Simon
In the Mouse library we have:

moves 
 : (
Position 
 
-> msg) -> Sub msg

Subscribe to mouse moves anywhere on screen. It is best to unsubscribe if 
you do not need these events. Otherwise you will handle a bunch of events 
for no benefit


*But how do I unsubscribe?* I can't think of a way to update the 
subscriptions in my Html.program record

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Status of Elm drag-and-drop with html elements

2016-11-22 Thread Simon
Is DragNDrop still something that needs ot be implemented with Mouse. There 
seems to be so much support for dragging built into Html directly that we 
ought to be able to do things more directly in Em by now I would have 
thought?

On Wednesday, 7 September 2016 20:19:25 UTC+2, Ivan Uemlianin wrote:
>
> Dear James
>
> Thanks, that is very helpful.  Thanks both.
>
> Before today I had the impression it might not be possible at all.
>
> From both of your help, I'll try and put together (& publish) something 
> that is just bare Elm, with a html  where you can draggingly re-order 
> the s.  
>
> Best wishes
>
> Ivan
>
>
> On Wednesday, September 7, 2016 at 6:04:58 PM UTC+1, James Wilson wrote:
>>
>> Ivan alas you need the server to get as far as being able to see the DnD 
>> in practise! it's a stack/haskell thing so if you happen to be using stack 
>> it's quite straight forward (scripts/run-server.sh should do 
>> most/everything). for the client, an npm install and then npm run build 
>> should be enough to build and put it into the place run-server expects. 
>> I'll make proper instructions at some point but the App isn't quite there 
>> yet :)
>>
>> failing getting things going, looking at the code should give a fair 
>> idea. I'm basically putting elements wherever I need to to capture the 
>> relevant events (what did I click on to start a drag? what is my current 
>> drag above/below/between if anything?). a little css (dnd.scss) makes sure 
>> the drag helper elements are in the right place. the list of html my 
>> Dnd.view expects has each item paired with a unique ID String so that my 
>> drag thing can use these IDs to track where the drag currently is between 
>> and inform the outside world. It also exposes a few functions that the 
>> outside world can use to query the current Dnd model to find out about 
>> things. I use this in Main.elm to decide when and where to render an 
>> overlay and what should be in the overlay.
>>
>> It's a little rough still but seems to work really reliably so far; I was 
>> looking for a solution that didnt break if you went a bit nuts throwing the 
>> mouse around etc! It's also 100% Elm which I'm pleased with. There are def 
>> things that Elm makes difficult that I had to work around, for instance 
>> finding exactly where in the item I clicked would be nice, but it's also 
>> hard (impossible?) in Elm if the element has children, as the mousedown 
>> event target isn't always the element you care about etc.
>>
>> Anyway, hope it helps :)
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] --debug with Navigation

2016-11-19 Thread Simon
Is it possible that the two are not compatible?  That's what it looks like 
with an App I have using Navigation - no sign of the debug menu until I 
revert to Html.program

SImon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: How do you test a TEA `update` function?

2016-11-07 Thread Simon
... which is ironic given all emphasis on 'effects as data'

On Monday, 7 November 2016 09:51:56 UTC+1, Austin Bingham wrote:
>
> I asked more or less the same question about a month ago and got no 
> responses:
>
> 
> https://www.reddit.com/r/elm/comments/593vua/how_to_test_the_complete_update_cycle/
> https://groups.google.com/d/msg/elm-discuss/634UXiZjRFQ/lVeDED1oBQAJ
>
> The only practical answer right now seems to be to use elm-testable, 
> though I haven't actually tried it myself.
>
> This feels like a real blind-spot in the elm ecosystem. The generation and 
> handling of Cmds is central to a properly functioning app, but there 
> doesn't seem to be any first-class way to test e.g. Update without driving 
> the entire app from the top-level. 
>
> On Mon, Nov 7, 2016 at 8:28 AM Simon <hotb...@gmail.com > 
> wrote:
>
>> I've often worried about the commands bit.
>> For the view side, you need to test that you are deriving the right data 
>> to render, while it is Evan that needs to test that, given certain data, 
>> expected DOM elements get produced?
>>
>>
>> On Monday, 7 November 2016 07:44:36 UTC+1, Francesco Orsenigo wrote:
>>>
>>> How do you write unit tests to ensure that an `update : Msg -> Model -> 
>>> ( Model, Cmd Msg )` function is producing the correct commands?
>>> What if the function is supposed to produce several commands batched 
>>> together?
>>>
>>> Same thing for a `view : Model -> Html Msg`.
>>> Suppose I want to test whether, given a particular model, it will 
>>> display the correct number of list items.
>>> Do people write tests for this?
>>> Right now the only way to write this kind of tests I can think of is 
>>> creating the whole html tree as I expect it to be rendered, and comparing 
>>> it via == with the function output.
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How do you test a TEA `update` function?

2016-11-06 Thread Simon
I've often worried about the commands bit.
For the view side, you need to test that you are deriving the right data to 
render, while it is Evan that needs to test that, given certain data, 
expected DOM elements get produced?

On Monday, 7 November 2016 07:44:36 UTC+1, Francesco Orsenigo wrote:
>
> How do you write unit tests to ensure that an `update : Msg -> Model -> ( 
> Model, Cmd Msg )` function is producing the correct commands?
> What if the function is supposed to produce several commands batched 
> together?
>
> Same thing for a `view : Model -> Html Msg`.
> Suppose I want to test whether, given a particular model, it will display 
> the correct number of list items.
> Do people write tests for this?
> Right now the only way to write this kind of tests I can think of is 
> creating the whole html tree as I expect it to be rendered, and comparing 
> it via == with the function output.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Interactive maps with Elm 0.17 : recommendation?

2016-11-05 Thread Simon
You won't find a library because you need access to native code. But I 
wrote a blog using Ports for 
0.16 http://simonh1000.github.io/2015/10/elm-architecture-ports/


On Thursday, 3 November 2016 17:16:08 UTC+1, dedo wrote:
>
> Relatively simple interactive usage to show markers on a map. 
>
> Any suggestions on which map library (google maps, leaflet, other) and 
> which Elm modules are a good starting point? Ideally something known to 
> work with Elm 0.17.
>
> The community packages list on elm-lang did not yield much.
>
> Thanks!
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Send a file via an ajax POST request

2016-11-05 Thread Simon
Hi guys, I'm the author for FileReader and the shortcoming you note is well 
known and currently unavoidable.  Please add you needs to this 
thread 
https://groups.google.com/forum/#!searchin/elm-discuss/blob|sort:relevance/elm-discuss/spr621OlUeo/UQq0rk0dBQAJ
 
 as we need to get WebApi implementations prioritised.


Simon


On Saturday, 5 November 2016 10:27:30 UTC+1, Martin DeMello wrote:
>
> Thanks, I took a look at that, but it loads the file data into elm, where 
> we still have the problem that we cannot attach a binary blob to a POST 
> request.
>
> I'm not fully sure, but I think the flow needs to be:
> 1. Get filename from the input button, in elm.
> 2. Pass filename to javascript
> 3. Upload the file and attach it to an ajax post request in javascript
> 4. Pass the return value of the ajax call back to elm
>
> martin
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Generating a batched Cmd of more than one msg from Task.perform

2016-10-19 Thread Simon
Sounds like you a recursively apply the update function, and that sounds 
like pretty solid functional programming


On Wednesday, 19 October 2016 11:51:16 UTC+2, Austin Bingham wrote:
>
> Is there a way to make Task.perform produce a batched "Cmd msg" on success 
> (or failure, for that matter)? I've got a case where, on success, I want to 
> send out more than one Msg, but because the success handler for 
> Task.perform can only generate one msg this isn't straightforward.
>
> What I'm doing now is creating an intermediate msg from the success 
> handler. When my update function handles this intermediate msg, it is then 
> able to generate the batched Cmd of two msgs that I want. This seems to 
> work well, but it feels like pattern that only exists because of 
> Task.perform's design.
>
> So, is there a better way? Am I missing something that would let me remove 
> this intermediate message, or is that just the way things have to work?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Access JS (ports?) from an Effects Manager

2016-10-13 Thread Simon
I want to build code to work with a well known JS library, and to make it 
reusable. I'm going to need some state that is ancillary to the core 
functionality, and thought about an Effects Manager.

I know we are normally directed towards Evan's Websocket library, but that 
uses Native code and gets Tasks that way.

As Native is otherwise banned, I obviously thought of Ports. However, 
Effects Managers work with Tasks, while ports return Cmds, and while 
.perform can turn a Task into a Command, the reverse does not seem 
possible. 

Comments? Does anyone have an example of an Effects Manager working via a 
Port?


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Debugging json decoders

2016-08-19 Thread Simon



My emulator may help - http://simonh1000.github.io/decoder/


On Friday, 19 August 2016 19:56:05 UTC+2, OvermindDL1 wrote:

On Friday, August 19, 2016 at 11:17:45 AM UTC-6, Sergey Zubtsovskiy wrote:
>>
>> Hey Jacob,
>>
>> Any update on this topic? I am facing the same issue, even in Elm 0.17 
>> with latest libraries...
>>
>
> You can setup multiple branches in a decode so it one fails then you can 
> fall back to a default value so it still passes.  You could even return a 
> Maybe and return a default value of Nothing if you want, wrapping the main 
> decode branch in a Just.
>
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Possible bug in Html

2016-08-16 Thread Simon
On Slack i was advised to use Html.Keyed and that fixed it
Thanks so much
Simon

On Tuesday, 16 August 2016 18:50:15 UTC+2, Wouter In t Velt wrote:
>
> My guess would be that this behavior is caused by changing from 3 to 2 
> options while doing the first selection.
>
> Chrome Inspector doesn't even show me the "selected" attribute.
> But with a static list of 3 items it works as expected 
> (change your view function to below to see)
> view model =
>   select
> [ onInput Switch ] <|
>[ option [ value "1"
> , selected <| model == Just "1"
> ] [ text "one" ]
>, option [ value "2"
> , selected <| model == Just "2"
> ] [ text "two" ]
>, option [ value "3"
> , selected <| model == Just "3"
> ] [ text "three" ]
>]
>
>
> My gut feel is that the virtual DOM diff engine is messing things up: on 
> the second render, elm knows you now have 2 instead of 3 options, but elm 
> does NOT know which of the original option has gone.
> You may want to check out Html.keyed, which is introduced specifically to 
> tackle this. 
> http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Keyed
>
> I copied the refactored code (with keyed) below. not sure if it solves 
> your issue though.
> Unfortunately, Elm-try does not recognize Html.keyed (yet).
> module Test exposing (..)
>
> import Html exposing (..)
> import Html.Keyed as Keyed
> import Html.App as App
> import Html.Attributes exposing (..)
> import Html.Events exposing (..)
>
> import List exposing (map)
> import Json.Decode as Json
>
> type alias Model =
> Maybe String
>
> init = Nothing
>
> type Msg
> = Switch String
>
> update (Switch s) model =
> Debug.log"" <| Just s
>
> view model =
> let
> kvs =
> [ ("1", "One")
> , ("2", "Two")
> ]
> -- makeOpts now returns List (String, Html Msg) to use in Html.
> keyed
> makeOpts lst selectedKey =
> lst
> |> map (\(k, v) ->
> (k, option
> [ value k
> , selected <| k == selectedKey
> ] [ text v ])
> )
> in
>   Keyed.node "select"
> [ onInput Switch ] <|
> case model of
> Just s ->
> makeOpts kvs s
> Nothing ->
> makeOpts
> (("0", "Zero") :: kvs)
> "0"
>
> main = App.beginnerProgram
> { model = init
> , view = view
> , update = update
> }
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Possible bug in Html

2016-08-16 Thread Simon
Would welcome some help and/or checking of this before I post as an issue. 
Try clicking on `One` and you should find yourself taken to "Two"

Simon

```
module Test exposing (..)

import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)

import List exposing (map)
import Json.Decode as Json

type alias Model =
Maybe String

init = Nothing

type Msg
= Switch String

update (Switch s) model =
Debug.log"" <| Just s

view model =
let
kvs =
[ ("1", "One")
, ("2", "Two")
]
makeOpts lst selectedKey =
lst
|> map (\(k, v) ->
option
[ value k
, selected <| k == selectedKey
] [ text v ])
in
select
[ onInput Switch ] <|
case model of
Just s ->
makeOpts kvs s
Nothing ->
makeOpts
(("0", "Zero") :: kvs)
"0"

main = App.beginnerProgram
{ model = init
, view = view
, update = update
}
```

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Collecting use cases for File, ArrayBuffer and TypedArrays/DataViews

2016-08-10 Thread Simon


I think this is the sort of code I would like to be able to write to do 
signed S3 uploads


FileReader API

readFile : FileRef -> Task Error Blob

and in the Http library

blobData : Blob -> Http.Data

such that

get ("signature" := string) "/get_signature"
`Task.andThen`
\sig -> 
readFile ref
`Task.andThen`
\content ->
let 
body = 
multipart 
[ ("signature", stringData signature)
, ("file", blobData content)
]
in
Http.send defaultSettings
{ verb = "POST"
, headers = [("Origin", origin)]
, url = "http://bucket-name.s3.amazonaws.com/;
, body = body
}
|> Http.fromJson ("ETag" := string)

On Saturday, 30 July 2016 21:06:55 UTC+2, Jan Weitz wrote:

I would like Binary decoders/encoders as John Watson  mentioned, as well.
>
>
> - Encoding/Decoding MQTT messages (which itself might contain Protobuf 
> messages) [
> http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718013
> ]
> - Encoding/Decoding Protobuf3 binary messages [
> https://developers.google.com/protocol-buffers/docs/encoding]
>
> Inspirations for native interfaces (for web or server-side) might be:
>
> - https://github.com/dcodeIO/bytebuffer.js [Native/bytebuffer.js and 
> ByteBuffer.elm]
> - https://github.com/dcodeIO/long.js
> - (https://github.com/dcodeIO/ProtoBuf.js) [Should be regular elm code]
> - (https://github.com/google/protobuf/tree/master/js/binary) [Should be 
> regular elm code]
>
>
>
> On Thursday, July 28, 2016 at 11:17:51 PM UTC+2, Daniel Bachler wrote:
>>
>> I'd love to see support for the File and ArrayBuffer Apis, and maybe 
>> TypedArrays/DataViews as well. IMHO they are an important piece of the Web 
>> Platform that is still missing in Elm.
>>
>> Evan suggested collecting concrete use cases to guide the design. I would 
>> like this thread to be the starting point of this effort. I would like to 
>> ask anyone who would also like this feature or who has substantial 
>> experience using either Api to add use cases or comment here so that we can 
>> try to define the user story for both apis. From there, we could decide 
>> what we would like to see supported and what, if anything, we don't need 
>> for now and suggest Elm Apis.
>>
>> I have two stories from a side project of mine. It is a slideshow editor 
>> that allows the user to select photos and audio files from the local 
>> system, uploads them to a web service, let's the user arrange and 
>> manipulate photos and music and then share the result with others. For 
>> this, I have two immediate use cases plus some more ideas:
>>
>> *Upload local files as binary blob to AWS S3*
>>
>> In my current, (hacky) version, I use the FileReader api (via 
>> simonH1000's filereader library) to read the content of a file into an 
>> ArrayBuffer, (represented as Json.Value in Elm) then use a modified version 
>> of elm-http to upload the content of the ArrayBuffer to an S3 storage 
>> bucket.
>>
>> *Download mp3 files, decode them and play them back via the AudioApi*
>>
>> Currently I do this with my modified http library to download the mp3 
>> file into an arraybuffer, then pass the resulting arraybuffer through a 
>> port to some native javascript that then uses the Audio Api to decode the 
>> mp3 file into a playable audiobuffer.
>>
>> *Parsing or otherwise processing local text files. *
>>
>> For another project I would be interested in reading and parsing 
>> Swagger/OpenAPI definition files and then providing a UI to compare rest 
>> apis. Since the processing will be done on simple Strings, this would only 
>> require FileReader support (specifically the readAsText method). This would 
>> already work with the FileReader library as is (though that one is not 
>> available on package.elm-lang.org because it contains native code and is 
>> not whitelisted).
>>
>> *TypedArrays and DataViews*
>>
>> I haven't worked with these yet, but I can anticipate some cases that 
>> would be interesting:
>>
>> *Parsing/manipulating of binary data via the ArrayBuffer api.*
>>
>> One case I personally would like to do with this, is to parse the Exif 
>> header of the jpeg files the user loaded from the local file system. My 
>> slideshow could then display metadata information without roundtripping to 
>> the server.
>>
>> *Create geometry for WebGL in the form of Vertex Buffers*
>>
>> *Generating sound/music by writing raw audio samples*
>>
>> These could then be played back via the Web audio apis.
>>
>>
>> Please add your own ideas to this thread. Once we have compiled a list of 
>> use cases, we can look at the JS Apis available under the Web Platform for 
>> Files, ArrayBuffers, Typed Arrays etc. and think how these could be exposed 
>> to Elm. 
>>

[elm-discuss] Is it possible to render an HTML form that works directly?

2016-08-10 Thread Simon
This is related 
to https://groups.google.com/forum/#!topic/elm-discuss/M6vbRoVSaG4 in that 
I'm trying to find work arounds to do signed uploads to S3.

In short, can I use Elm to render a POST form with a `file` input and a 
submit button that 'just works' - i.e. the POST takes place directly and 
uses the browsers filereader and multipart building functionality directly, 
with Elm just sitting back and watching it happen?

I think the answer is yes, but I'l be left with no control over the 
browser's subsequent redirecting. Any ideas on whether that can be 
caputured and turned into an event that can be passed back to Elm through a 
port?

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Chaining and Task with a Port request

2016-08-10 Thread Simon


As we have to use ports to access the FileReader API, I’m facing the 
situation where I want to do the equivalent of 

http.get ("signature" := string) "/api/signature" 
`Task.andThen` (\sig -> sendS3 sig)
|> Task.perform

where port sendS3Cmd : String -> Cmd msg

Clearly this does not type check, but I’m wondering whether there any ways 
to chain these side effects other than waiting for the upload function to 
be recalled?
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: What would need to happen to implement Blob/File in Elm.http?

2016-08-09 Thread Simon
Hi, I see you do not implement readAsArrayBuffer. Isn't that the most 
flexible for binary data?
Simon

On Wednesday, 6 July 2016 05:27:50 UTC+2, Gusztáv Szikszai wrote:
>
> It takes two (
> https://github.com/gdotdesign/elm-ui/blob/master/source/Ui/Native/FileManager.elm#L74):
>  
> first is the key (String) which is "file" and the second is the file object 
> which goes through here 
> https://github.com/gdotdesign/elm-ui/blob/master/source/Native/FileManager.js#L48
>  
> which actually returns a File 
> <https://developer.mozilla.org/en/docs/Web/API/File> but with a type of 
> String so Http.stringData 
> <http://package.elm-lang.org/packages/evancz/elm-http/3.0.1/Http#stringData> 
> can 
> accept it.
>
> Sadly ports have very strict border protection as described here 
> http://guide.elm-lang.org/interop/javascript.html so there is no way that 
> a File can be passed through them, that is the main reason a native module 
> is needed. 
>
> On Tuesday, July 5, 2016 at 8:23:38 PM UTC+2, Simon wrote:
>>
>> Hi
>> I’m not sure I want to adopt native code as such, but I already need to 
>> use ports, so I’d like to learn from what you have. I’m struggling to follow
>>
>> https://github.com/gdotdesign/elm-ui-guide/blob/master/examples/file-upload.elm#L55
>> FileManager.toFormData "file" file
>> as toFormData appears to take only argument?
>>
>> What am I missing?
>>
>> Simon
>>
>> On Tuesday, 5 July 2016 06:10:18 UTC+2, Gusztáv Szikszai wrote:
>>
>> Funnily enough the Http package doesn't need to change in order to allow 
>>> file uploads. 
>>>
>>> I already made this work for Elm-UI, as I described here 
>>> https://gdotdesign.gitbooks.io/elm-ui-guide/content/guides/handling_files.html
>>>  
>>> the Http package uses FormData 
>>> <https://developer.mozilla.org/en/docs/Web/API/FormData> to send 
>>> multipart forms and FormData allows appending files, so the only thing 
>>> needed is to tricking it to accept the File object as a String because 
>>> that's the only supported Http.Data 
>>> <http://package.elm-lang.org/packages/evancz/elm-http/3.0.1/Http#Data>
>>>  type.
>>>
>>> The main problem is how to get the File 
>>> <https://developer.mozilla.org/en/docs/Web/API/File> and for that I 
>>> created the FileManager 
>>> <https://github.com/gdotdesign/elm-ui/blob/master/source/Ui/Native/FileManager.elm>
>>>  (with 
>>> a native module 
>>> <https://github.com/gdotdesign/elm-ui/blob/master/source/Native/FileManager.js>)
>>>  module, 
>>> basically it allows selecting single / multiple files and returns a record 
>>> that contains information about the file and the raw File object itself and 
>>> then there is the toFormData method which converts it to Http.Data, 
>>> masquerading the File as a String.
>>>
>>> And that is all, you can see a working example here: 
>>> https://github.com/gdotdesign/elm-ui-guide/blob/master/examples/file-upload.elm
>>>  
>>> (it needs Elm-UI)
>>>
>>> If that wasn't clear I'm happy to explain it in more detail. 
>>>
>>> Unfortunately this still using native modules and although it can be 
>>> separated into a standalone module I see no way that it will be white 
>>> listed soon, let's just hope installing packages directly from Github will 
>>> come soon.
>>>
>>> On Monday, July 4, 2016 at 11:45:29 PM UTC+2, Daniel Bachler wrote:
>>>>
>>>> Hi Simon,
>>>>
>>>> here you go: https://github.com/danyx23/elm-http/commits/encode-as-json
>>>> As I said, it's hacky and I haven't gotten around to updating to 0.17, 
>>>> but for 0.16 for my purposes it worked :)
>>>>
>>>> Daniel
>>>>
>>>> -- 
>>>> Daniel Bachler
>>>> http://www.danielbachler.de
>>>> <http://www.danielbachler.de/contact>
>>>>
>>>> On 4 July 2016 at 13:07, Simon <hotb...@gmail.com> wrote:
>>>>
>>>>> I'd love to look at what you did. I have run into this issue, or at 
>>>>> least think I have in that i need to create a multipart element and 
>>>>> https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_forms_through_JavaScript
>>>>>  
>>>>> suggests I need a different sort of content boundary than `Http` foresees 
>>>>> (`blob` rather than `--WebKitFormBounda

[elm-discuss] Re: Scrolling to bottom of div

2016-07-19 Thread Simon
the alternative is to use a `Tick` or `Time.now` such that a command 
returns immediately and allows you to run the port command in the first 
possible cycle after the virtual DOM has been rendered

On Tuesday, 19 July 2016 22:28:01 UTC+2, Wayne Choi wrote:
>
> I guess it's a small price to pay. 
>
> On Tuesday, July 19, 2016 at 12:42:25 PM UTC-7, Frederick Yankowski wrote:
>>
>> It's just a heuristic that someone came up with. It's short enough to be 
>> almost imperceptible but long enough that the updated element should be 
>> settled in the browser.
>>
>> On Tuesday, July 19, 2016 at 1:02:59 PM UTC-5, Wayne Choi wrote:
>>>
>>> Thanks, Frederick.. is there a reason something special about 50? 

 ​

>>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Elixir users: have you made Brunch work?

2016-07-12 Thread Simon
Hi, I've built a couple of projects now using Phoenix and Elm, but both 
quickly started misbehaving in that the file watchers were not picking up 
changes properly and causing recompilation. I'm thinking of substituting in 
Gulp next time as I know it is reliable, but wanted to see whether I have 
missed something. I've been following Alan Gardner's blog 
(http://www.cultivatehq.com/posts/phoenix-elm-2/)

Simon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Stuck on custom event handlers and JSON decoder for select element

2016-07-08 Thread Simon


With 0.17 I use onInput

On Friday, 8 July 2016 14:47:01 UTC+2, Adam Waselnuk wrote:

This is the last thing blocking me from a migration to 0.17. I can't seem 
> to wrap my head around capturing an on "change" event from a select 
> element. At this point my app is compiling, but when I toggle the select 
> dropdown, no messages are sent to the update function. If anyone can point 
> me to further reading on any of these topics I would very much appreciate 
> it. 
>
> I have also created a Gist of the relevant (I think) code if anyone has a 
> minute to check that out: 
> https://gist.github.com/AWaselnuk/d0c9a01931c6e8e8a84d8743b6739df2
>
​

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Authentication & Session Management

2016-07-07 Thread Simon
I wrote this a short while 
ago http://simonh1000.github.io/2016/05/phoenix-elm-json-web-tokens/


On Wednesday, 6 July 2016 21:48:58 UTC+2, Erik Lott wrote:
>
> Yup, I understand passing down config (context) data down through the 
> update methods so they can be used in http requests.
>
> What's not clear to me is how you are using this technique in terms of 
> authentication. BTW: I'm generally a systems & server dev, so I'm likely 
> bringing that baggage with me.
>
> Here are some things that are not clear to me:
>
>1. Digging through elm app source code, I often see a "Maybe 
>currentUser" field stored directly on the root model, and I that's fine. 
>Let's say I also have a nested LoginComponent for my UI, and this 
> component 
>does not have access to that root model (this is sort of obvious). When a 
>user uses this component to successfully authenticate themselves (the 
>LoginComponent makes the http request with the server), how am I then 
>communicating a successful login back up to the root model? Should the 
>LoginComponent directly return some data from it's update method - like 
>this 
>
> 
>?
>2. If a nested component receives an 401 response back from the API, 
>how should I then propagate that response back up to the root so that the 
>current user can be logged out (currentUser = Nothing)?
>
> Am I thinking about this in the wrong way?
>
>
>
> On Wednesday, July 6, 2016 at 3:12:54 PM UTC-4, Scott Corgan wrote:
>>
>> Here's an article that elaborates a bit more: 
>> https://www.brianthicks.com/post/2016/07/05/duplicate-message-or-update-contexts-in-elm-components/
>> .
>>
>> Then, in each parent's update function, you are calling the child's 
>> update function. But, instead of just calling "ChildComponent.update msg 
>> model", you'll call "ChildComponent.update context msg model"
>>
>> Does that help?
>>
>>
>> On Wed, Jul 6, 2016 at 2:57 PM Erik Lott  wrote:
>>
>>> Can you explain how this works?
>>>
>>>
>>>
>>>
>>> On Wednesday, July 6, 2016 at 2:37:57 PM UTC-4, Scott Corgan wrote:

 It seems like the easiest approach at this point is a combination of 
 binding a context type as the first argument to your update functions and 
 sending the Navigation.newUrl command from the updateUrl function (used by 
 Navigation).

 urlUpdate : Context -> Navigation.Location ->  ( Model, Cmd a )

 and the rest of the update functions:

 update : Context -> a -> Model -> ( Model, Cmd a )

 On Wednesday, July 6, 2016 at 2:05:25 PM UTC-4, Erik Lott wrote:
>
> *Is there an idiomatic/proven way to approach Authentication in an Elm 
> single page app?* Sadly, there are very few resources online that 
> touch on authentication, yet it's an unavoidable part of SPA development. 
> It would be great if this discussion could serve as the best answer to 
> this 
> question.
>
> In our case, I am evaluating Elm for a Single Page Application. We 
> have a simple json api, as follows:
>
> The API:
>
>
>- POST /sessions  - post a username/password. If the credentials 
>are authentic, it returns 200 OK along with a secure http-only cookie.
>- GET /me - returns 200 OK with user record or 401 Unauthorized
>
>
> Our Elm requirements:
>
>- When the client app loads, it makes a request to /me to see if 
>the user is currently logged in. If 200 OK, store the current user in 
> elm 
>and display to the Dashboard page. If not, display the login page.
>- On a successful login, make a request to /me to retrieve the 
>current user record, store the current user in elm, and display 
>the Dashboard page.
>- If an API response ever returns 401 Unauthorized, remove the 
>current user record on the elm model, and display the login page
>
>
> I'm sure that any guidance from community would be appreciated by all!
>
>
> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elm-discuss...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Bubbling Http Errors from Nested Components

2016-07-05 Thread Simon
I suggested option 1 and use it all the time. In practise I enable commands 
in the root and first couple of children (basically components that equate 
to a table in my database), and then turn to pure update functions 
thereafter, and catch "Submit" events at the lowest parent that does 
command handling. It works for me, and then I use the update function to 
pass back returned data into my children's models. I've wondered about the 
triple return `update` function, but I think it would make refactoring 
quite a bit more painful.

Simon

On Tuesday, 5 July 2016 19:30:51 UTC+2, Mark Hamburg wrote:
>
> The first option feels repugnant from an encapsulation standpoint. I've 
> built the second option and it works but it increases the amount of 
> boilerplate in hierarchical systems because we now have three results to 
> deal with in update functions. That's lead me to think about but not yet 
> write a command alternative that could also handle tasks that didn't need 
> to be routed back to the originator and that could be used to send messages 
> to the top-level (or elsewhere). That said, once one gets into replacing 
> Cmd, the API request model makes a lot of sense.
>
> Mark
>
> On Jul 5, 2016, at 5:46 AM, Erik Lott <mreri...@gmail.com > 
> wrote:
>
> My app has several layers of nested components. Various components 
> throughout the tree will need to interact with our API via http requests. 
> If any API request returns a 401 - Not Authorized error, or a Timeout 
> Error, the error needs to bubble up to the root component where is can be 
> handled appropriately.
>
> What is the most idiomatic way of dealing with this? 
>
> *1. Parent should pattern match against important child messages*: 
> Reference 
> <https://groups.google.com/d/msg/elm-discuss/QPqrJd4C78Y/_TLLg81SAQAJ>
> This could work, but would be unreasonable in this case. The root 
> component would need to match against every failing api http request made 
> by every child, grandchild, great-grandchild, etc, component in the tree. 
> If a single pattern is missed, the app would be in an error state, so this 
> is prone to mistakes.
>
> *2. Nested Components return additional info from the "update" function*: 
> Reference 
> <http://stackoverflow.com/questions/37328203/elm-0-17-how-to-subscribe-to-sibling-nested-component-changes>
> Each component returns an additional value from its update function like 
> this:
> update : Msg -> Model -> (Model, Cmd Msg, SomeInfo)
>
> The parent component could inspect the returned "SomeInfo" value from its 
> direct children, and act on that information if necessary.  In my case, any 
> nested component that makes http requests to our API would be responsible 
> for returning a APINotAuthorized and APITimeout value to its parent, and 
> its parent would do the same, until the error has bubbled up to the root 
> component.
>
>
> Option 2 is simple and robust, and can be used to pass messages of any 
> type, for any situation... but I'm wondering if I'm missing an obvious 3rd 
> solution?
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to elm-discuss...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: What would need to happen to implement Blob/File in Elm.http?

2016-06-27 Thread Simon
Daniel 
did you ever make progress on this?
Simon

On Monday, 7 December 2015 20:47:32 UTC+1, Daniel Bachler wrote:
>
> Hi,
>
> Simon and I extended his Filereader library ( 
> https://github.com/simonh1000/file-reader ) over the last few days to 
> read binary files as well as text files. There are now 3 methods: 
> readAsText, readAsArrayBuffer and readAsDataURL. One of the examples makes 
> use of a Dropzone where you can drop images, then readAsDataURL is used to 
> read an image as a dataURL (=base64 encoded) and assign that to an img src 
> tag. The roundtripping of values from the event is done with a decoder that 
> decodes the files as a Json.Values and uses that to pass it into one of the 
> readAs* functions.
>
> But as Simon wrote in this ticket 
> https://github.com/simonh1000/file-reader/issues/12 , the most 
> interesting use case for readAsArrayBuffer would be to upload straight 
> binary file - and this doesn't work right now because Elm.http lacks 
> support for Blob/File (
> https://github.com/evancz/elm-http/blob/3.0.0/src/Blob.elm is just a 
> stub).
>
> I don't know that much about Elm yet, so I want to ask more knowledgeable 
> people here: what would it take to implement a Blob/File Api for Elm.http? 
> Is it mostly about providing type definitions and handling the 
> corresponding cases in Json.Decode/Json.Encode? If that is all I would see 
> if I can come up with a solution and send a PR, but I'd like to know how 
> deep the water might be before I get started with something like this :)
>
> Also, Elm.http does not have a Contributing file, is there a general one 
> for big important Elm libraries?
>
> Daniel
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Support for binary data

2016-06-27 Thread Simon
I need to be able to upload PDFs
Simon


On Tuesday, 21 June 2016 19:56:07 UTC+2, Yosuke Torii wrote:
>
> I need binary things too for two cases, uploading files and Web Audio. 
> These are not special things.
>
> I'd like to know the plans, when it is most likely to come (or how these 
> features are prioritized).
>
>
> 2016年6月21日火曜日 19時36分59秒 UTC+9 John Mayer:
>>
>> I took a shot at starting a basic version of this in my fork of websocket 
>> and a new package simply called binary. My approach was largely thin 
>> wrappers on top of the spec.
>>
>> Evan, is your draft public? No updates from you since January. IMHO, 
>> don't try to carry this one yourself. This is an opportunity to spread the 
>> load and develop yourself as a manager of contributors while building out 
>> the process for accepting large contributions.
>> On Jun 21, 2016 6:09 AM, "Gábor Varga" <gva...@gmail.com> wrote:
>>
>>> This feature would come handy for me too.
>>> Our use-case is that we get some encrypted data from an MQTT broker and 
>>> it might be broken up to several messages. 
>>> The binary data first has to be reassembled before it can be converted 
>>> to UTF8 encoded strings.
>>>
>>>
>>>
>>>
>>> On Thursday, April 7, 2016 at 1:18:17 AM UTC+2, Ian Mackenzie wrote:
>>>>
>>>> I'd love to have ArrayBuffers supported for doing WebGL stuff. For 
>>>> rendering very large and complex scenes, I think it would be useful to be 
>>>> able to do a lot of the heavy lifting (level of detail and occlusion 
>>>> calculations etc.) on the server, and then just send compact ArrayBuffers 
>>>> to the client that could be passed directly to 
>>>> WebGLRenderingContext.bufferData() or similar (via an Elm wrapper, 
>>>> presumably, but without any parsing/conversion/copying).
>>>>
>>>> On Tuesday, 12 January 2016 11:32:43 UTC+11, Evan wrote:
>>>>>
>>>>> I have been drafting Blob and ArrayBuffer APIs, but I wasn't sure who 
>>>>> needed them.
>>>>>
>>>>> What is your particular use case?
>>>>>
>>>>> On Mon, Jan 11, 2016 at 4:55 AM, John Watson <john@gmx.co.uk> 
>>>>> wrote:
>>>>>
>>>>>> Can anyone tell me what the plans are for supporting binary data in 
>>>>>> elm?  I'm thinking of a Byte (and some sort of Byte Array) type and also 
>>>>>> implementing Blob in HTTP responses. 
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Elm Discuss" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to elm-discuss...@googlegroups.com.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elm-discuss...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Managing global state in Elm

2016-06-01 Thread Simon


This is super cool.
But what is the function:

(!) : a -> List b -> (a, b)

On Wednesday, 1 June 2016 09:45:05 UTC+2, James Wilson wrote:

Thanks for your help; I'll have a ponder and probably end up taking an 
> effect manager route again (I started this way and then ended up with some 
> weird hybrid where my cache was in the main elm app and an effect manager 
> did the "lower level" api stuff; but I'm not so happy with it)
>
> As another effect manager code point if you're intrigued how they work 
> (and my comments are in any way useful, which they may not be); here's an 
> effect manager I made for sending and receiving things from a backend I'm 
> wiring my app up to (so it uses custom Cmds and Subs):
>
>
> https://github.com/jsdw/tl-asset-browser/blob/3e9e8527f65ae0a0a2d5d00d01779bdfdf03701d/src/elm/Api.elm
>
> Not sure whether it's any help (may just be easier looking at the elm-lang 
> effect managers!) but just in case :)
>
> On Wednesday, 1 June 2016 08:31:11 UTC+1, Peter Damoc wrote:
>>
>> I haven't used an effect manager for this because I haven put in the time 
>> needed to learn how to create effect managers. :) 
>>
>> If what I've shown here can be accomplished with an effect manager then 
>> that's the way it should be done.  :) 
>>
>>
>>
>>
>>
>>
>> On Wed, Jun 1, 2016 at 10:21 AM, James Wilson  wrote:
>>
>>> Thanks, that looks like basically exactly what I'd have guessed :) It's 
>>> super useful seeing an actual code sample with these ideas in.
>>>
>>> One thing I wonder now is; why not use an effect manager for this? It 
>>> basically seems to fit the exact same space (allows you to create a custom 
>>> Req like thing that can be mapped and batched and passed up the component 
>>> hierarchy - except that it's just a Cmd instead and plays nice with other 
>>> Cmds; allows you to maintain and update state (the cache) as you go; allows 
>>> you to "convert" Reqs to tasks to be run - just Cmds again now). In fact, 
>>> effect managers don't really seem to help you do anything other than what's 
>>> described here (plus a subscription side if you want it). Are there any 
>>> cons to using an effect manager here that you have in mind?
>>>
>>> On Tuesday, 31 May 2016 20:43:41 UTC+1, Peter Damoc wrote:

 The updating of the cache sounds to me like this: 

 1. if we have the info in cache, just supply the info without a HTTP GET
 2. if we don't have the info in cache, return a different Msg that 
 encapsulates the msg that requested the original information and the info 
 required for the cache update. 

 Here is a quick update of the code I've previously posted to include 
 this caching mechanism. 

 https://gist.github.com/pdamoc/d492ab58023926cd4d4950f12e5e170d




 On Tue, May 31, 2016 at 10:05 PM, James Wilson  
 wrote:

> The key part that's not coded in the gist is the use of a cache/global 
> state object, however I think I  see what you're getting at - pass back 
> up 
> the chain a Req object, say, and at the top we can turn it into a Cmd 
> using, say, some top level global state as well as whatever other data we 
> need. This may lead to a request being made to the server or it may not.
>
> The other part of the puzzle is actually updating the cache when a 
> request is made. Req.toCmd for instance could return an updated 
> GlobalState 
> so that it's able to cache "pending" states on values (so that we can 
> avoid 
> duplicating requests). To update the cache when the response actually 
> comes 
> in we could have toCmd return a Cmd.batch of 2 commands, one that will 
> fail/succeed and send a message to the component that initiated the Req, 
> and one that will send a message aimed at the top level cache itself.
>
> Thanks Peter, I'll definitely mull over this!
>
> On Tuesday, 31 May 2016 19:45:42 UTC+1, Peter Damoc wrote:
>>
>> ADT in Elm is one of its most powerful weapons. 
>>
>> You could encapsulate your requests in a type and use this type at 
>> top level to fulfill them. 
>>
>> For example: instead of returning Cmd msg you return some Req msg 
>> that can be turned into a Cmd msg at top level based on some context 
>> information. 
>>
>> Here is a gist with a skeleton of how I view this implemented:
>> https://gist.github.com/pdamoc/a47090e69b75433efa60fe4f70e6a06a
>>
>> I've sent the base of the URL as a simple String in `Req.toCmd` but 
>> you can imagine a more complex type holding all kind of information 
>> (e.g. 
>> cache, auth, etc ) . 
>> Also, I've kept the type of the Req simple (only saved the rest of 
>> the URL based on the user and the request) but one could use it to store 
>> all the info needed when you will turn the Req into a Cmd. 
>>
>>
>>
>>
>>
>>

[elm-discuss] Re: How can I do module level configuration?

2016-05-27 Thread Simon
I'm building quite a large app at present and find myself passing more and 
more into the view functions in addition to that component's model. I feel 
reassured knowing that the view function can't mess with any state and the 
diffing engine is ensuring that I'm not causing more DOM work than 
necessary. 

The inability to capture even micro amounts of state in components will 
either be one of Elm's long term contributions to front end programming or 
part of its eventual sidelining by a broader community - I don't know which 
though.



On Friday, 27 May 2016 07:28:57 UTC+2, Ian Mackenzie wrote:
>
> I think the first solution (context/options argument) is the clearest and 
> simplest. Yes, it's a bit verbose, but:
>
>- You can use the 'view' and 'viewWithOptions' pattern where the 
>former calls the latter with a default primary color etc., so you can get 
>convenience if you don't care about customizability
>- Users can easily do something like `myView = viewWithOptions 
>myOptions' in their own code and then just use that partially-applied 
>function everywhere (with the advantage that they can control exactly 
> where 
>and how the partial application happens)
>- It's very clear what's going on - one of the things I love about Elm 
>is that it's much easier than other languages to trace the flow of logic 
>and see how things work without having to worry about hidden/implicit 
> state 
>or context. Creating a module-like record seems to move a little ways in 
>the 'magic' direction...
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Nested components and async JS via ports

2016-05-25 Thread Simon


I have something like

type Msg = ParentMsg Id Child.Msg

My data is in Dicts and my views look like

Dict.map \i v -> Child.view v |> Html.map (ParentMsg i)

On Wednesday, 25 May 2016 15:05:34 UTC+2, Erik Simmler wrote:

I have a rather gross implementation of what I'm hoping to achieve. I don't 
> really see a way to do this without writing Native code, which is highly 
> unfortunate: https://github.com/tgecho/elm-custom-task-example
>
> On Friday, May 20, 2016 at 2:03:42 PM UTC-4, Erik Simmler wrote:
>>
>> Thanks! ...but I don't think I explained my question very well. I'll try 
>> to come up with some sort of explanatory sample code when I have some time 
>> back at my computer, but in the meantime...
>>
>> In your sample, you're only nesting the component once. In my case I have 
>> more than one child of the same type (e.g. the nested counter/gif 
>> examples). I'm looking for a good way to return a Cmd from a child to 
>> javascript through a port, do some async work in JS and route a Msg with 
>> the result back to the same child.
>>
>> The Gif/Http/Task workflow seems to be really close to the result I want 
>> which is why I brought it up.
>>
>>
>> On Friday, May 20, 2016 at 12:57:38 PM UTC-4, Peter Damoc wrote:
>>>
>>> Keep your ports in one file and import that file throughout your 
>>> project. 
>>>
>>> Here is a gist with a simple example:
>>> https://gist.github.com/pdamoc/bf346e232ae2466923c18101122e3690
>>>
>>> download and  
>>>
>>> $ elm-make Main.elm --output elm.js
>>>
>>> agree to the install of the packages and after the elm.js is produced, 
>>> open index.html
>>>
>>> you should be able to see the classic counter and it should work as 
>>> expected with one small change, the update of the counter is done with a 
>>> round trip through JS. 
>>>
>>> The way I've set up this to work is by creating a port `toJS` where I 
>>> send String 
>>> in index.html, I check to see if the String is "Increment" and send back 
>>> through `fromJS` either +1 or -1 
>>>
>>> In Component I subscribe to `fromJS` and feed this +1 or -1 back into 
>>> the counter update. 
>>>
>>> As you can notice in Main... there is no knowledge in the parent about 
>>> what the Component is actually doing. All the parent does is map things and 
>>> pass around messages just like in any other regular Elm Architecture thing. 
>>>
>>> One last thing. Please note in Ports.elm that the Cmd and Sub you have 
>>> there are generic. 
>>>
>>> This way, the Ports.elm doesn't need to import anything. 
>>> Also, as I've demonstrated in Main.elm you can subscribe to those ports 
>>> from other parts of the App, even with different purposes. I've subscribed 
>>> in Main just to snoop on what's going on there. :) 
>>>
>>>
>>>
>>> On Fri, May 20, 2016 at 5:59 PM, Erik Simmler  wrote:
>>>
 Does anyone have a good pattern for handling multiple nested components 
 that need to communicate with JS via ports/subscriptions?

 I have a list of items, and I'm trying to allow any of these children 
 to send a message through a port and receive the result back via a 
 subscription. I have the outgoing port and incoming subscription wired up 
 and functioning (using `Sub.batch` similarly to 
 https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/4-gif-list.elm#L150),
  
 but any message I get back through the port from JS land is duplicated for 
 each child.

 Furthermore, I can't come up with a nice way to get them tagged and 
 directly properly without moving the ports up to the containing component 
 and "manually" wrapping/unwrapping the commands and messages, which seems 
 like an unfortunate level of coupling.

 In the elm-architecture-tutorial repo, the Gif component requests a new 
 url by returning a command created by `getRandomGif` (
 https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/Gif.elm#L53).
  
 In the second nesting example, the only relevant place that I can see any 
 mapping occurring is the usual `Cmd.map` at 
 https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/4-gif-list.elm#L93.
  
 Yet, when the `FetchSucceed` comes back, it is properly wrapped in a 
 `SubMsg Int` message.

 This seems to be exactly what I want, but I can't figure out how it 
 works. How I can replicate this effect on my own or am I just barking up 
 the wrong tree? Thanks!

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Elm Discuss" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to elm-discuss...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> -- 
>>> There is NO FATE, we are the creators.
>>> blog: http://damoc.ro/
>>>
>> ​

-- 
You received this message because you are subscribed to the Google 

[elm-discuss] WebSocket and Phoenix Channels

2016-05-22 Thread Simon
Tucked away in WebSocket.LowLevel 
<http://package.elm-lang.org/packages/elm-lang/websocket/1.0.1/WebSocket-LowLevel>
 
is an appeal to (I presume) Chris McCord to build a library to connect Elm 
with Phoenix. Pending Chris taking up the challenge I have started 
exploring the Elm-Phoenix 
<http://simonh1000.github.io/2016/05/elm-phoenix-channels/> space. If 
anyone wants to co-create on a library for the community, I'd welcome some 
collaboration.

Simon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Elm, Phoenix and Jwt-based authorisation

2016-05-21 Thread Simon
Hi, 
I have just posted an update to elm-jwt 
<http://package.elm-lang.org/packages/simonh1000/elm-jwt/latest> together 
with a post 
<http://simonh1000.github.io/2016/05/phoenix-elm-json-web-tokens/> on how 
to use it with a Phoenix server. I'm using this successfully in a project 
currently under construction and wanted to share experience.
Simon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Json decoding an event target

2016-05-17 Thread Simon
I'm trying to get the text of the selected `option` in a `select` dom 
element.

temp1 is the event object from a change in the select and you can see what 
values it exhibits in devtools 

<https://lh3.googleusercontent.com/-DO4L7c0yz9w/Vzr0ibYdthI/AeA/NflDdALarqwCG5QF_eBbu8epQzFgTJkBQCLcB/s1600/Screenshot%2Bfrom%2B2016-05-17%2B12-27-16.png>

`selectedOptions` is an array of 1 item


<https://lh3.googleusercontent.com/-QpzSifzJtAw/Vzr02tb68iI/AeE/fH1BAotnRV4LrnfyQCUS-6qoegL38urLgCLcB/s1600/Screenshot%2Bfrom%2B2016-05-17%2B12-33-02.png>
So I expected  `Json.at ["target", "selectedOptions"] <| Json.tuple1 
identity ("text" := Json.string)` to work, but it does not.

Any advice?

Simon

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.