-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make class properties observable #104
Conversation
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.
Good start @cherifGsoul!
src/mixin-props-test.js
Outdated
@@ -20,3 +20,61 @@ QUnit.test("basics", function(assert) { | |||
el.age = "33"; | |||
assert.equal(el.age, 33, "updated age"); | |||
}); | |||
|
|||
try { |
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 think all of the tests that require class fields should go in their own file. Then the main test file can do this feature detection and create a variable like supportsClassFields
. The wrap the require
statement for the tests like
if(supportsClassFields) {
require(...);
}
src/mixin-props-test.js
Outdated
QUnit.test('Class fields should be observable', (assert) => { | ||
class DefineElement extends mixinDefine(Object) { | ||
greetings = 'Hello'; // jshint ignore:line | ||
static get props() { |
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.
Are props
required?
src/mixin-props-test.js
Outdated
const el = new DefineElement(); | ||
|
||
if (el.hasOwnProperty('greetings')) { | ||
el.initialize(); |
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.
You should probably check that the default value is correct.
src/mixin-props-test.js
Outdated
el.initialize(); | ||
|
||
el.on('greetings', () => { | ||
assert.ok('The class field is observable'); |
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.
Can you also check that the value and old value are correct?
src/mixin-props-test.js
Outdated
} | ||
|
||
const el = new DefineElement(); | ||
el.initialize(); |
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.
You also need to check the value of greetings
to make sure the precedence is correct.
src/mixin-props-test.js
Outdated
assert.ok('The class field is observable'); | ||
}); | ||
|
||
el.greetings = 'Hola'; |
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.
After this you should also check that setting the value to a non-string causes an error.
src/mixin-props-test.js
Outdated
assert.ok('The class field is observable'); | ||
}); | ||
|
||
el.greetings = 'Hola'; |
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.
Can you also check that setting the value to a non-string works since expando properties like this are not typed.
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.
Added some comments on the docs.
Will review the code separately.
docs/can-stache-element.md
Outdated
@@ -206,6 +206,31 @@ document.body.querySelector("button#remove").addEventListener("click", () => { | |||
@codepen | |||
@highlight 14-23,only | |||
|
|||
|
|||
#### Observable class fields |
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.
Can you move this under the Defining an element's properties
heading?
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.
Done!
docs/can-stache-element.md
Outdated
|
||
#### Observable class fields | ||
|
||
`StachElement` class fields are observables like [can-stache-element/static.props static props], |
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.
Can you link class fields
to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_fields?
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.
Done!
docs/can-stache-element.md
Outdated
</script> | ||
``` | ||
@codepen | ||
@highlight 11,only |
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.
The highlighting is off here.
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.
Fixed!
docs/can-stache-element.md
Outdated
<button on:click="this.increment()">+1</button> | ||
`; | ||
|
||
count: 6 |
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.
This should be count = 6;
.
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.
Done!
docs/can-stache-element.md
Outdated
count: 6 | ||
} | ||
customElements.define("count-er", Counter); | ||
</script> |
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.
Can you also add a note in that you must either add the element to the page or call initialize
in order for the prop
value to be observable?
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.
Done!
@phillipskevin I updated the docs! |
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.
Just a couple small comments.
docs/can-stache-element.md
Outdated
@codepen | ||
@highlight 11,only | ||
|
||
In order to make `count` property observable, either `count-er` element must be added to the page |
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.
Can you put this in a blockquote? >
and add Note:
to the beginning?
docs/can-stache-element.md
Outdated
@@ -135,6 +135,33 @@ customElements.define("count-er", Counter); | |||
@codepen | |||
@highlight 9-11,only | |||
|
|||
#### Observable class fields | |||
|
|||
`StachElement` [class fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_fields) like [can-stache-element/static.props static props], |
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 think this is missing some words.
class fields are observable like...
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.
Also, I would just leave off the like static props
piece. Just
StacheElement class fields are also observable.
...along with the example should be fine for now.
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.
Found one more issue.
test/test.js
Outdated
if (supportsClassFields) { | ||
//It doesn't work with require | ||
//Even when change the above imports to require | ||
steal.import('~/src/mixin-props-class-fields-test'); |
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 just tried this out in the canjs/canjs suite and this file can't be loaded since the ~
is the canjs
folder. We'll need to figure out how to do this.
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.
It looks like you added steal-conditional and created the supports-class-fields module, but it is not being used to import the class field test file.
Also, there are still a couple issues with the docs that need to be cleaned up.
@phillipskevin I updated the docs |
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.
A couple more small things.
docs/can-stache-element.md
Outdated
@@ -135,6 +135,33 @@ customElements.define("count-er", Counter); | |||
@codepen | |||
@highlight 9-11,only | |||
|
|||
#### Observable class fields | |||
|
|||
`StachElement` class fields are also observable., |
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.
can you add the link to class fields docs on MDN?
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.
@phillipskevin Done!
test/test.js
Outdated
@@ -1,3 +1,14 @@ | |||
let supportsClassFields; |
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.
This can be removed now, right?
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.
@phillipskevin Done!
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.
🎉
This makes class properties observable:
In case of:
It set the value of
props.greetings
by the classe property value.For canjs/can-observable-mixin#79