-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Method to scan for and register stylesheets #2233
Method to scan for and register stylesheets #2233
Conversation
61d730e
to
2b8d0b3
Compare
fe474d3
to
7834694
Compare
less.sheets.push(links[i]); | ||
} | ||
} | ||
if (i === links.length - 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as calling resolve at the end of the function? Would that be simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye aye, fixed. Thanks.
less.refresh(less.env === 'development'); | ||
less.registerStylesheets().then( | ||
function () { | ||
less.refresh(less.env === 'development'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less.refresh does the actual transformation, so does less.refresh need to return a promise and then this line here returns that so the promises are chained?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, my other PR includes the promise for refresh(). Should I merge it and make the changes you propose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heading out, I'll be back on this on Fri.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll Look later, I can't figure this out on my mobile..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeh I got confused between the 2 pull requests.. thought they were 1...
7834694
to
d31be57
Compare
Method to scan for and register stylesheets
Hope you don't mind, I made a few tweaks. renamed hasFinished to pageLoadFinished and made it explicit that it will be available immediately (and not changed). |
Awesome thanks! Glad we got it knocked out. Id like to beef up the browser docs as well. Any where specific you need help? |
Fantastic, yes there is a v2 branch on less-docs - there are basic |
Ehm, so just a practical question, does this allow unloading specific stylesheets as per #771? Because as far as I can see this does not, yet that issue states it has been fixed in this pull. |
Hi @Greats. This PR addresses the need to dynamically load and unload stylesheets, albeit using a different method than the one detailed in #771. This PR allows you to rescan the DOM after having added or removed stylesheets using some traditional templating means. I'm using AngularJS' After you have the stylesheets you want on the page (not limited to the less.registerStylesheets().then(
function () {
// The new stylesheets have been loaded.
// Now refresh() or modifyVars() to parse the changes.
less.refresh();
}
); Let me know if you're able to get this working with your use case. |
Problem
As web apps become more dynamic developers are now finding they have the need to load/unload stylesheets dynamically. Currently, less does one initial scan for stylesheets on load. This means less will not parse stylesheets added dynamically after page load, even when calling
less.refresh()
orless.modifyVars()
.Proposed Solution
Make the stylesheet loading code available as a method, returning a promise. On resolve, you can
.then()
call aless.refresh()
orless.modifyVars()
: