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

automatically calling tagHandler for tags in the document #77

Merged
merged 4 commits into from
Jan 12, 2018

Conversation

phillipskevin
Copy link
Contributor

first piece of #75.


//!steal-remove-start
var requestedAttributes = {};
//!steal-remove-end

var tags = {};

var GLOBAL = getGlobal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't cache this. Even thought this feature will (likely) never run in SSR, having this here might mean someone else uses it in code that will.

var mountedElements = new WeakSet();

var mountNodeAndChildrenIfNecessary = function(node) {
var tagName = node.tagName && node.tagName.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: node.localName is already lower case

};

var obs = new MutationObserver(mutationHandler);
obs.observe(GLOBAL.document.documentElement, { childList: true, subtree: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use getGlobal or getDocument

};

var mountExistingElements = function(tagName) {
var nodes = GLOBAL.document.getElementsByTagName(tagName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getGlobal or getDocument

@matthewp
Copy link
Contributor

I'm a little confused about the flow here. How is anything ever added to mountedElements? Only .has() is ever used, in which case it will always be empty, no?

@phillipskevin
Copy link
Contributor Author

phillipskevin commented Jan 12, 2018

mountedElements will be used by stache. Basically, stache will add elements it has rendered to the mountedElements Set so they do not need to be rendered twice.

@matthewp
Copy link
Contributor

What does "mounted" mean exactly? Does it mean that the tag handler has been called on it?

@phillipskevin
Copy link
Contributor Author

Yes. If in mountedElements, we won't call tagHandler.

@phillipskevin
Copy link
Contributor Author

I'm open to ideas for a better name.

@matthewp
Copy link
Contributor

So in that case do we need stache to do the job of adding to mountedElements? Can callbacks not do it here?

var helperTagCallback = tagData.scope.templateContext.tags.get(tagName),

@phillipskevin
Copy link
Contributor Author

Yes, you're right we can do it there. I don't think we need the viewModel check either. I'll update the code and tests.

@phillipskevin phillipskevin merged commit a9f1514 into major Jan 12, 2018
@phillipskevin phillipskevin deleted the automatic-mounting branch January 12, 2018 23:28
@matthewp
Copy link
Contributor

🎉

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.

None yet

2 participants