Feature request: do-block syntax

Open
#32 0 comments 0 reactions 0 assignees View on GitHub

@schneiderfelipe is already working on this.

Since May 20, 2021.

  • #34 by @schneiderfelipe — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
frontend

Research direction

Start by reading the proposed (x::Hyperscript.Node)(f::Function, args...; props...) method and the existing Node call behavior. Verify the nested do-block example in the issue works while the current argument-based syntax remains unchanged; the payload names no files or tests, so locate the relevant implementation and test entry points first.

Written by the indexing model from the issue text.

Description

Hi @yurivish, how do you feel about adding a do-block syntax (similar to markaby)? That would allow one to write the following:

using Hyperscript

@tags div em a

# What I'm proposing:
div.header() do
    a(href="https://github.com/yurivish/Hyperscript.jl") do
        em("Hyperscript.jl")
    end
end

instead of

# Current equivalent:
div.header(a(href="https://github.com/yurivish/Hyperscript.jl", em("Hyperscript.jl")))

or, equivalently,

# Indented current equivalent:
div.header(
    a(href="https://github.com/yurivish/Hyperscript.jl",
        em("Hyperscript.jl")
    )
)

That could increase readability in general. Of course, nothing would break; it would only be an alternative way of writing things.

If you like it, I could make a PR 😀

EDIT: a single line is all that's required to make the example above work:

julia> (x::Hyperscript.Node)(f::Function, args...; props...) = x(args..., f(); props...)

julia> div.header() do
           a(href="https://github.com/yurivish/Hyperscript.jl") do
               em("Hyperscript.jl")
           end
       end
<div class="header"><a href="https://github.com/yurivish/Hyperscript.jl"><em>Hyperscript.jl</em></a></div>
Dominant language
Julia
Stars
105
Forks
12
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaWeb/Hyperscript.jl

All issues in JuliaWeb/Hyperscript.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.