Skip to content
This repository was archived by the owner on Oct 12, 2020. It is now read-only.

proposal: simplify apiΒ #345

@lifeart

Description

@lifeart

We could go this ways:


<div {{ref "field"}} ></div>
class Component {
  @ref("field") node = null;
}

where {{ref "field"}} will be transformed to {{ref this "field"}},
and @ref decorator will control property access (and will throw error if property does not yeat setted), it should fix all tracked issues.

one more interesting thing, we can share refs between components (we could add ability to have "global" refs), in this case, we will use @ref("field") to access ref-bucket, and we can introduce {{ref-for "field"}} helper, and it can return actual dom node, with same ref.

it may be {{global-ref "footer"}}, @globalRef("footer"), {{global-ref-to "footer"}}

in therory "ref-bucket" approach may simplify dom ref usages for template-only components, for example

<div {{ref "field"}}>hello</div>

{{get (ref-to "field") "textContent"}}

<SecondComponent @helloNode={{ref-to "field"}} />

example: https://github.com/lifeart/ember-ref-bucket

<div {{bound-to this.getNode}}></div>
class Component {
   getNode() { return null }
}

quite straightforward usage, we will patch getNode method on this during modifier initialization, and getNode will return value or null.


<div {{ref-to this.node}}></div>
class Component {
   node = null;
}

and check for this.node property descriptior (it shoud be simple, without getters/setters )


@jrjohnson @simonihmig @wycats what do you think? Any suggestions, additions?

// related duscussion -#232

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions