Skip to content

feat: setProperty on Observable#8521

Merged
vtrifonov merged 3 commits into
NativeScript:masterfrom
rigor789:feat-unknown-attributes
Apr 14, 2020
Merged

feat: setProperty on Observable#8521
vtrifonov merged 3 commits into
NativeScript:masterfrom
rigor789:feat-unknown-attributes

Conversation

@rigor789
Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

Right now when unknown properties are added/set on a View, css attribute selectors do not update the styling.

What is the new behavior?

A new setProperty method has been added to Observable that will fire a propertyChange and a ${propertyName}Change event - which will get picked up by the css runtime and styles will update.

The reason I've opted for a new method is because the set method of the Observable is overwritten in Views - adding a new method allows triggering the correct events.

Ref: #6122, #7914

@cla-bot cla-bot Bot added the cla: yes label Apr 12, 2020
@rigor789
Copy link
Copy Markdown
Member Author

I'm a bit unsure if this will be usable in other frameworks setAttribute equivalent.

I'm thinking of doing
if(property in targetView) -> just set it, and the Property setter will fire,
else -> call targetView.setProperty(..) to force css updates by emitting propertyChange and {propertyName}Change events.

Would the property in targetView check work in all cases? hasOwnProperty returns false for ones added with a Property.

@rigor789 rigor789 marked this pull request as ready for review April 12, 2020 00:18
Comment thread api-reports/NativeScript.api.md
Comment thread api-reports/NativeScript.api.md
Comment thread nativescript-core/data/observable/observable.ts
Comment thread nativescript-core/data/observable/observable.ts
Comment thread nativescript-core/data/observable/observable.ts Outdated
Co-Authored-By: Vasil Trifonov <v.trifonov@gmail.com>
@rigor789 rigor789 requested a review from vtrifonov April 13, 2020 19:17
@vtrifonov vtrifonov merged commit 7cf3c97 into NativeScript:master Apr 14, 2020
NathanWalker pushed a commit that referenced this pull request Aug 7, 2020
* feat: setProperty on Observable

* refactor: add missing whitespace

Co-Authored-By: Vasil Trifonov <v.trifonov@gmail.com>

Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
NathanWalker pushed a commit that referenced this pull request Aug 7, 2020
* feat: setProperty on Observable

* refactor: add missing whitespace

Co-Authored-By: Vasil Trifonov <v.trifonov@gmail.com>

Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants