-
Notifications
You must be signed in to change notification settings - Fork 7
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 a build that allows for ES module use #8
Conversation
This adds a build so that custom-attributes can be used as an ES module. ```js import { customAttributes, CustomAttributeRegistry } from 'custom-attributes'; ``` The above imports each, without anything being set on the `window`. If you just want the registry you can do: ```js import CustomAttributeRegistry from 'custom-attributes/registry'; ``` and create your own instance. The same script tag will still work which sets the global: ```html <script src="./node_modules/custom-attributes/attr.js"></script> ``` Closes #7
// chlidList | ||
else { | ||
forEach.call(m.removedNodes, downgrade); | ||
forEach.call(m.addedNodes, upgrade); |
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.
forEach
is now undefined - think it was at the top of the file? Also I'm pretty sure mutations
passed to the observer callback is already an Array so should only need the forEach.call
on the above two lines.
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.
Yep, CI caught this as well, will update.
Nice! Only thing I find a bit odd is how I can get import { CustomAttributesRegistry } from 'custom-attributes' Is it worth maybe leaving out |
index.js
Outdated
|
||
var customAttributes = new CustomAttributeRegistry(document); | ||
|
||
export { customAttributes, CustomAttributeRegistry } |
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.
@matthewp what do you think of using:
export default customAttributes
export { CustomAttributeRegistry }
?
Import interface then:
import customAttributes, { CustomAttributeRegistry } from 'custom-attributes';
Personally, like the idea of customAttributes
being the default there, with CustomAttributeRegistry
as a kind of extra utility.
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.
Yeah, agree, will update.
Yeah, the reason I left in custom-attributes/registry was in case you didn't want a default customAttributes for the global document. But if you don't need that I'll just remove the second import. |
@matthewp for me personally, no - though thanks for the consideration! 😄 |
Oh apologies - I just re-read that. Right, yeah for my use case I'm looking to not have a global registry added by default. Yeah perhaps it is worth keeping in a separate file by default? Certainly feels cleaner to have it all bundled into one file. Is there much downside to having the default registry setup, even if you're not going to use it? |
@bedeoverend I think we can keep I guess the downside would be that MutationObservers are set up. |
This restructures the API so that customAttributes is the default.
@bedeoverend Ok, I updated it so that the API now works like: import customAttributes, { CustomAttributeRegistry } from 'custom-attributes'; Or if you don't want the global document to be set up: import CustomAttributeRegistry from 'custom-attributes/registry'; Sound good? |
@matthewp LGTM - thanks! |
Released as 1.1.0 |
Awesome - thanks @matthewp! |
This adds a build so that custom-attributes can be used as an ES module.
The above imports each, without anything being set on the
window
. Ifyou just want the registry you can do:
and create your own instance.
The same script tag will still work which sets the global:
Closes #7
cc @bedeoverend