-
Notifications
You must be signed in to change notification settings - Fork 0
Simplified API (open to discussion) #3
Comments
Thanks for the ping. Gonna dive into the above this week and I'll follow up. |
tl;dr: this makes a ton of sense. I'm excited for the next update.
These make a ton of sense.
Are there ever cases in which a key could exist multiple times? For instance if you've added multiple event handlers for the same action? In that case would the library remove both (seems sensible)?
I like
That's a really good question. I can see arguments both ways. As far as I remember, we've never needed to look at (or change) fields on the record directly in our code. (Have you?) It's sometimes been useful to dump the record to the console, but you can still do that with an opaque type (AFAIK). The risk of making it opaque is that people might run into situations that can't be handled by the existing methods, in which case new framework methods would be needed. The risk of exposing it is that people might write code that depends on implementation details, making it either painful or impossible to change the implementation later. Personally, I think the risks of exposing the details are much greater. Modular UI lives on top of Virtual Dom, whose implementation could change in ways that might be best handled by changing the data structure; if that's opaque, it's easy, whereas if it's been exposed that could potentially cause a lot of pain. Compared to that, having to add methods occasionally doesn't seem to bad. One way to make sure that people don't get stuck could be to make it possible to give a node raw
👍
I think this is really sensible terminology that'll make the library clearer.
Would it make sense to have a
👍
To make sure I understand how this would work, would it be myNode
|> Ui.addChild parentNode
-- return an updated parentNode? That works for me. It would still be possible to write code like myNode
|> Ui.addChild (Ui.element "div")
|> Ui.addClass "foo" It's a little more verbose (I can't promise we wouldn't create |
Thanks for your input, @arsduo. 1. Implementation of
VirtualDom handles duplicate keys in an appropriate way, so my approach has been to preserve duplicates and hand them over to VirtualDom. It makes sense where the list is preserved in an 2. Package / core module name See #4. Also: I'd like to avoid confusion with mdgriffith/elm-ui. Alternative suggestions welcome. 3. Exposed vs. opaque type
I agree with this reasoning, and I think we can guarantee that there will be a modifier function for anything useful you could do with basic record updates. I do think it makes sense to include functions for adding child nodes from 4. Removing a generic attribute
I would need to be convinced that this capability is really useful to have. I think it will make the package easier to learn if generic attributes (i.e., not classes, styles, actions) are added via 5. Adding child nodes
I think you might have this backwards. I intended it to be:
or
Now I am also thinking that the
etc. |
Started assembling the module here. |
Here's a somewhat final list of exposed functions: Create and Render
BuildUsing a single argument...to set the id attribute
to add a class, style, or other attribute
to add an event listener
to append or prepend internal text
to append or prepend a child element
Using a list argument...to add a list of classes, styles, or other attributes
to append or prepend a list of child elements
you can also supply a list of
or a keyed list for performance optimization
Using a conditional parameter...when adding a class, style, or other attribute
when adding a list of classes, styles, or other attributes
when adding an event listener for an action
when appending or prepending internal text
when appending or prepending child elements
ModifyRemoving all instances of a single name or key
Replacing the existing list of classes, styles, or other attributes
Replacing the existing text
Replacing the existing descendant tree
Advanced UsageSetting an element's HTML/XML tag and namespace
Customizing event handling...by transforming input values
by using a custom decoder
by using custom handler optionsstop propagation
prevent default
both
Debug
|
That covers everything I can think of. It certainly should be enough for me to reimplement the drag-and-drop functionality, as well as everything we've done at eSpark. Looking forward to the new API! |
wow this is going to be fantastic. SUPER excited for this release!!! Sorry if i missed this somehwere but will this be tied with or integrated by default with Bulma? |
No, I'm taking a different approach here. After considering what seemed to be most useful out of my earlier attempts, I started to see the end goal differently. The new package is intended to be a basic set of utilities for UI development in Elm, which will not be tied to a specific CSS framework or component library. In other words, instead of creating components for others to use, my aim is to provide utilities that make it easier for users to build the customized components they need. At the same time, I want to support other package developers in creating libraries of reusable components, so my secondary goal is to make this package a comprehensive and reliable base for those efforts. That said, some of the functionality of the previous Modular UI package may be incorporated into new packages in the future, so let me know if there are other parts you have found particularly useful that are not included here. |
The new package is published under |
Awesome! We're at ElmConf now, funnily enough, so I'll take look soon :)
…On Wed, Sep 26, 2018, 12:48 Daniel Narey ***@***.***> wrote:
@arsduo <https://github.com/arsduo> @carolineartz
<https://github.com/carolineartz>
The new package is published under visotype/elm-dom! I'm releasing it
under my organization name to differentiate it from my more experimental
personal projects. The docs are here:
https://package.elm-lang.org/packages/visotype/elm-dom/latest/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC8xcybMFudw-HbeY3ccxw68FXT-rcBks5ue73agaJpZM4Wdg1U>
.
|
ohhhhhh awesome!! can't wait to check it out. Was hoping you'd be at Elm Conf! |
Requesting input from @arsduo, @carolineartz, and other users:
Background and motivation
Read here if you are interested.
Semantics of record updates
When argument is a single value or key/value pair:
add__
= append a value or key/value pair to the current list contained in a fieldadd__Conditional
= same asadd__
, but only updates when a conditional expression evaluates toTrue
remove__
= delete all instances of a value or key from the current list contained in a fieldreplace__
= delete the current value contained in a field, replacing it with the new valueWhen argument is a list:
add__List
= append a list to the current list contained in a fieldadd__ListConditional
= same asadd__List
, but only updates when a conditional expression evaluates toTrue
replace__List
= delete the current list contained in a field, replacing it with the new list (to remove the current list, just replace it with[]
)Variations for particular fields:
set__
= same asreplace__
, but signals that field that should only need to be updated onceappend__
andprepend__
= used instead ofadd__
to provide an option for inserting the argument before or after the field's current string/listCore module
Discussion of name is in issue #4
Types:
Constructor for element records:
This replaces
leaf
,textWrapper
, andcontainer
with a single constructor. The string argument sets the tag. See below for how to add child nodes.Modifier functions for attributes:
In the previous version, "modifier" had a specific meaning pertaining to style classes that modify a base class. In the new version, I want to use "modifier" to mean any function that takes an existing element record, updates some of its internal data, and returns the updated element record. I'd like to call these "modifier functions" instead of "update functions" to make clear that they are just part of the view code and don't have anything to do with the Elm program's
update
function.Modifier functions for internal text:
Text is rendered to VirtualDom as the first child node, containing plain HTML text. Helper functions for styling text that were included in the previous version will be moved to a separate package.
Modifier functions to construct an element's internal tree:
Child elements are immediately rendered to VirtualDom when this function is executed.
setChildListWithKeys
uses theVirtualDom.KeyedNode
optimization and should only be called once on any given node.Modifier functions to set tag and namespace
The tag is already set with the
element
constructor function, but it could be useful to be able to change it when using component libraries. Namespace would typically be used to construct SVG nodes. Whenever the namespace field is not an empty string,VirtualDom.nodeNS
is used for rendering.Rendering
This function only needs to be called on the root node of a tree.
VirtualDom.Node
is interchangeable withHtml.Html
.The text was updated successfully, but these errors were encountered: