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

Eventmaps implemented #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

jankapunkt
Copy link
Contributor

After reading through the gh code of the Blaze repo I found that I can traverse the parentView tree upwards until I find the surrounding Template. So no additional parameters required.

The good thing is that there is always a parent Template to be found, so there should be no case where the while loop is causing an infinite.

To be on the safe side I could add a counter and throw an Error if it reaches the 10000 or so. What do you think?

Once the parent view has been found we can access it's Template with the __eventMaps property and assign it to the contentBlock.

Finally we assign the parent views templateInstance to the newly created view. Otherwise the second parameter in the event callback would not have the scope of our parent Template's instance.

I could not write a test to check for the proper templateInstance within the Template.dest.events part, mainly because I get circular errors and I think this is due to the test environment. What do you think?

@arggh
Copy link
Owner

arggh commented Jan 9, 2019

Thank you for working on the solution!

I finally had a chance to take a look and the implementation seems brilliant. However, I noticed, that this change causes the issue I previously mentioned: the normal event bubbling from child components inside the teleported block is changed and an event stopped in the child component's handler somehow still ends up in teleport's parent's handler.

Minimalistic example:

<template name="app">
  <h1>Clicked {{counter}}</h1>
  {{#Teleport ''}}
    <button type="button">App click</button>
    {{> clicker ''}}
  {{/Teleport}}
</template>

<template name="clicker">
   <button type="button">Clicker click</button>
</template>
Template.app.onCreated(function () {
  this.counter = new ReactiveVar(0);
});

Template.app.events({
  'click button'(event, instance) {
    instance.counter.set(instance.counter.get() + 1);
  },
});

Template.clicker.events({
  'click button'(event) {
    event.stopPropagation();
  }

Now, clicking on the Clicker click button shouldn't cause an increase in the counter, but it does. If you remove the Teleport block helper, Clicker click no longer increases the counter.

src/teleport.js Outdated Show resolved Hide resolved
src/teleport.js Outdated Show resolved Hide resolved
src/teleport.js Outdated Show resolved Hide resolved
src/teleport.js Outdated Show resolved Hide resolved
@jankapunkt
Copy link
Contributor Author

jankapunkt commented Jan 10, 2019

@arggh I fixed the semicolons. For the event bubbling it will take a while, because I think we also need to test, if the other event properties (target, defaultTarget, currentTarget, cancelable etc.) are working, too.

I will consider a test function for that, first.

Edit: as I need this feature especially with events in combination with Bootstrap modals I will check also if it breaks the modal events, too and hopefully be able to deduce a more generic test from it.

@jankapunkt
Copy link
Contributor Author

I am a bit stuck at work but I keep track of this and come back, once finished with current tasks.

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

Successfully merging this pull request may close these issues.

2 participants