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

Unobserve attributes #3

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

Conversation

semmel
Copy link

@semmel semmel commented Nov 21, 2019

For wrapping attribute changes in my reactive streams I needed a way to unsubscribe the callback again.
This PR also adds a few tests around onAttributeChanged.
(I did not quite understand the need for the additional jest tests, why is karma not sufficient?)

Hope all this is non-breaking since I use the return value of onAttributeChanged which is up to now not documented.
I did not build the doc files, just edited the sources.

I needed to bump karma-rollup-preprocessor because the old is not compatible with my more recent rollup.

@HenriqueLimas
Copy link
Owner

@semmel thank you very much for the PR. Sorry for the delay, for some reason I am not receiving notifications for this repo.
Could you run npm run prettier to format the file properly?

Also regarding roll-up, in theory running npm run build will use the roll-up version set as a dependency of the project so we do not need to update it.

@@ -34,7 +34,7 @@ This is invoked when an attribute from the `observedAttributes` list is added, c
removed. This could be useful to make network request for updating the data.

```javascript
onAttributeChanged(element, ({ name, current }) => {
let unsubscribe = onAttributeChanged(element, ({ name, current }) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we use const instead of let here? Since is not going to change it make more sense a const.

Copy link
Author

Choose a reason for hiding this comment

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

Done - no problem.

element = document.querySelector('attribute-test-element');

onAttributeChanged(element, ({name, current, old}) => {
if (name !== "foo") {
Copy link
Owner

Choose a reason for hiding this comment

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

We could use a mock function and check if that function was called or not called in the other test. In that way the test will be simpler and we don't need to throw errors

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I don't get it 🤔. Could you describe it more?

@semmel
Copy link
Author

semmel commented Dec 15, 2019

Could you run npm run prettier to format the file properly?

I did that, but I could not find any differences :-/

$ npm run prettier

> [email protected] prettier /Users/Semmel/Documents/Projects/WebLibraries/semmel/osagai/branches/unobserve-attributes
>prettier --write 'lib/**/*.js'

lib/core/morphdom/index.js 46ms
...
lib/lifecycles/onDisconnected.js 4ms

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