Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model.item to Event #78

Open
ghost opened this issue Apr 16, 2017 · 1 comment
Open

Add model.item to Event #78

ghost opened this issue Apr 16, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 16, 2017

Declarative event handlers inside a "dom-repeat" add the model object to the event. If we make the model available on the elemental.Event then it is possible to get the data from the item when an event is fired.

@JsType(isNative=true, namespace=GLOBAL)
public interface Event {
     ....

    @JsProperty TemplateInstance getModel();

    @JsType(isNative=true, namespace=GLOBAL)
    public interface TemplateInstance {
        @JsProperty <T> T getItem();
    }
}

Example:
So if the "dom-repeat" template contains an event handler (a.e. <paper-button on-tap="onTapFct">) then we get the binded data on each event.

Polymer.function(bindTemplate, "onTapFct", event -> {
    Foo foo = ((Event) event).getModel().getItem();
});

final List<Foo> data = createData();
repeatTemplate.setItems(Polymer.asJsArray(data));
@ibaca
Copy link

ibaca commented Sep 9, 2017

IMO Accessing to this field using some static utility make much more sense. The model is only available if the handler is in a dom-repeat, this cannot be expressed using the type-system so it just better to force the user to call the method itself. This actually matches perfectly with the alternative strategy proposed by polymer this.$.domRepeat.modelForElement(event.target).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant