Giter VIP home page Giter VIP logo

svelte's People

Contributors

antony avatar aphitiel avatar benmccann avatar btakita avatar btk5h avatar colincasey avatar conduitry avatar dependabot[bot] avatar ekhaled avatar emiltholin avatar evs-chris avatar fweinb avatar garrettgeorge avatar jacobmischka avatar jacwright avatar jamesbirtles avatar jches avatar lukeed avatar mindrones avatar mrkishi avatar panya avatar paulbgd avatar pngwn avatar rich-harris avatar sanderhahn avatar swatinem avatar tanhauhau avatar tehshrike avatar tivac avatar zxbodya avatar

Watchers

 avatar

svelte's Issues

New feature: fragments

Issue

To do conditional wrappers, one has to repeat code.

Example:

<script>
    let first = 'first';
    let second = 'second';
    let third = 'third';
</script>

{#if wrap}
    <div>
        <div>
            <span>{first}</span>
            <span>{second}</span>
            <span>{third}</span>
        </div>
    </div>
{:else}
    <span>{first}</span>
    <span>{second}</span>
    <span>{third}</span>
{/if}

But this would also be true for small pieces of code being repeated often and for which a full custom component would not be the most practical solution.

Proposal

<script>
    let first = 'first';
    let second = 'second';
    let third = 'third';
</script>

{#fragment block}
    <span>{first}</span>
    <span>{second}</span>
    <span>{third}</span>
{/fragment}

{#if wrap}
    <div>
        <div>
            {#include block}
        </div>
    </div>
{:else}
    {#include block}
{/if}

A fragment should also support scoping, and therefore could be defined inside a {#each} block and use the local bindings. It would be reused inside that block and only inside that block.

Concerns

A fragment definition disrupts with the usual semantics: it defines a piece of content which is not displayed where it's defined.

Also the design scope should be clear, simple and straightforward: custom components should be the solution as much as possible!

Alternatives

Use a custom component, but it would be nice to have one bound to a set of input properties (because otherwise it's not resilient to have to repeat the values all the time). Otherwise, right now, since this component sole purpose would be to serve as a fragment, the context feature could be used, but still not the most practical.

However, I don't know how it would fit with local template variables (i.e. in {#each}) anyways...

New feature: allow slots to target any piece of markup

Issue

For now, slots can be filled only by a DOM element, e.g.: <h1 slot='slotname'>any content</h1>.

This can enter in conflicts with the design of some CSS frameworks (with a very specific expected DOM structure) and preventing the reuse of generic components then.

It is also surprising this can't be added on custom elements...

Besides all that, using an attribute for that purpose could potentially enter in conflict in case that attribute would be relevant on an element, primary or custom.

Proposal

Introduce a {#slot slotname}{/slot} statement, which would solve all issues: allows text nodes only, allows list of elements, allows custom components.

It's also very concise and logical and there's already the code base to support such statements (it's like if, each and so on).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.