What is the status of this? I really need the functionality in one of my 
projects.

Thanks
-- Cezar

On Thursday, November 26, 2015 at 12:59:32 PM UTC+2, Jan Dudek wrote:
>
> Thanks, I really like the proposal, as I already had to use NoOps several 
> times. (Although none of my codebases was a “serious” project).
>
> Hopefully this gets implemented in elm-effects.
>
> On Thursday, November 26, 2015 at 11:45:17 AM UTC+1, Janis Voigtländer 
> wrote:
>>
>> Concerning the first issue you mention: The feature I propose for 
>> elm-effects here <https://github.com/evancz/elm-effects/issues/28> 
>> should allow you to get rid of the need for NoOp.
>> ​
>>
>> 2015-11-26 11:20 GMT+01:00 Jan Dudek <[email protected]>:
>>
>>> Hi!
>>>
>>> After a discussion on elm-dev (
>>> https://groups.google.com/forum/#!topic/elm-dev/G9FGTAyHATk) I’ve 
>>> implemented an Elm wrapper for Clipboard.js.
>>>
>>> Clipboard.js (http://clipboardjs.com/ & 
>>> https://github.com/zenorocha/clipboard.js) is a library that allows to 
>>> copy text to clipboard when the user clicks an element. You can either 
>>> specify text to copy or an element where the text will be copied from.
>>>
>>> Here’s the source code & examples:
>>> * http://jdudek.github.io/elm-clipboard/
>>> * https://github.com/jdudek/elm-clipboard
>>>
>>> It includes some native code, so it’s not available on 
>>> http://package.elm-lang.org/ yet. It’s also my first Elm package, so I 
>>> hope I haven’t screwed anything up :)
>>>
>>> I’m looking for feedback, especially on the following issues:
>>>
>>> 1) Handling initialization
>>>
>>> Clipboard.js attaches an event handler to the document root. This has to 
>>> be done once per page. Currently I do it as an effect returned from `init`, 
>>> i.e.:
>>>
>>> init =
>>>   let
>>>     model = …
>>>
>>>     fx =
>>>       Effects.task <|
>>>         Clipboard.initialize ()
>>>         `andThen` (\_ -> succeed NoOp)
>>>         `onError` (\_ -> succeed NoOp)
>>>   in
>>>     (model, fx)
>>>
>>>
>>>
>>> However, this is a bit cumbersome to the user. I’d love to ged rid of 
>>> `andThen` and `onError` here, and also to avoid having to define `NoOp`, 
>>> which has to be later handled in the update function. The only solution I 
>>> can think of at the moment is calling `initialize` in native code, when the 
>>> native wrapper is being imported—but I don’t know if it’s acceptable for a 
>>> native module to have such side effects.
>>>
>>> If it’s not, I’m wondering if there is a way to avoid having to define 
>>> NoOp by the component that uses Clipboard.
>>>
>>> 2) Using event handlers
>>>
>>> I cheated a little bit by using `on` from `elm-html` to bind a function 
>>> to a DOM node. This is later called as a regular function, not as a DOM 
>>> event: 
>>> https://github.com/jdudek/elm-clipboard/blob/master/src/wrapper.js#L26-L30
>>>
>>> However, I couldn’t find any other way to receive a message to address 
>>> given in a view—and using addresses makes the API really simple for the 
>>> user.
>>>
>>> 3) Runtime safety & API design
>>>
>>> Clipboard.js uses `data-` attributes, like `data-clipboard-text`, to 
>>> enable its behavior. My wrapper adds helpers for setting these attributes.
>>>
>>> There are illegal combinations, e.g. you shouldn’t set both 
>>> `data-clipboard-text` and `data-clipboard-target`. The first one is the 
>>> text you want to copy, the second gives an element from where the text will 
>>> be copied; it doesn’t make sense to have both. Clipboard.js raises a 
>>> runtime exception when such combination happens.
>>>
>>> I’m thinking if there is a way to avoid such exceptions by having a 
>>> better API. For instance, instead of setting attributes, we could have a 
>>> function that takes a Node and adds necessary attributes:
>>>
>>> button [] [ text "Copy!" ]
>>>   |> clipboardText "Text to copy" address Success
>>>
>>>
>>> button [] [ text "Cut!" ]
>>>   |> clipboardTarget "#foo" Clipboard.Cut address Success
>>>
>>> But in order to implement such functions, I’d need to deconstruct given 
>>> DOM Node, append some attributes and return altered node—and I haven’t 
>>> found a way to do it.
>>>
>>> In theory I could wrap the user’s element in another one, with clipboard 
>>> attributes, but I’d like to avoid that. Such wrapper elements in DOM may 
>>> cause problems when styles depend heavily on DOM structure, e.g. with 
>>> sibling selectors or flex boxes.
>>>
>>> The last option I see is to have a function that accepts all clipboard 
>>> arguments + desired element, it’s attributes and content. E.g.:
>>>
>>> let
>>>   clipboardButton = clipboardTextElement button 
>>> in
>>>   clipboardButton "Text to copy" address Success [] [ text "Copy!" ]
>>>
>>>
>>> But I’m not entirely convinced if it’s a good API.
>>>
>>> Any thoughts?
>>>
>>> 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 [email protected].
>>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to