color-js / elements

WIP
12 stars 1 forks source link

[color-swatch] Update the corresponding custom CSS properties on the `gamuts` change, fixes #79 #80

Closed DmitrySharabin closed 3 months ago

DmitrySharabin commented 3 months ago

In the dependency graph, the order of props also matters—gamuts should be updated before color.

netlify[bot] commented 3 months ago

Deploy Preview for color-elements ready!

Name Link
Latest commit 4da136343b486f0a11eb5bb6128a6cc28a3f085d
Latest deploy log https://app.netlify.com/sites/color-elements/deploys/666074bfa508a4000837ff15
Deploy Preview https://deploy-preview-80--color-elements.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

LeaVerou commented 3 months ago

Why?

DmitrySharabin commented 3 months ago

Some more results of my investigation: The propChange event for gamut is fired only once when color is set, but not when the gamuts changes. This is incorrect: If gamuts change, the properties of the current gamut might also be changed, and these changes should be reflected.

Now, it should be fixed for real. Thank you for your question, which allowed me to investigate the problem deeper. 🙏

LeaVerou commented 3 months ago

Hmm, I’m still not sure this is the right way and not a workaround. If the gamuts change in a way that affects the current gamut, a propchange should fire for gamut too…

DmitrySharabin commented 3 months ago

If the gamuts change in a way that affects the current gamut, a propchange should fire for gamut too…

That was one of my guesses during the investigation, too. But this event didn't fire up, and I thought it shouldn't. Obviously (now, at least), it should. So, yeah, you are right—this is more of a workaround.

LeaVerou commented 3 months ago

Can we investigate why it doesn't fire? It sounds like it could be a Nude Element bug.

DmitrySharabin commented 3 months ago

Can we investigate why it doesn't fire? It sounds like it could be a Nude Element bug.

Sure. Will do it now

DmitrySharabin commented 3 months ago

I knew it! I had a feeling that the real reason is in this.

So, the sequence of actions is the following:

As I can conclude, nothing is wrong with how NudeElement works (it works great).

What if we rename gamutInfo to gamut (and get rid of the old one) and work with it all over the <gamut-badge> code?

LeaVerou commented 3 months ago

Ah, so gamut depends on this.gamutInfo.id, but because the object this.gamutInfo didn't change, NudeElement doesn’t realize its property may have changed, right?

Just making sure I got it right before suggesting solutions.

LeaVerou commented 3 months ago

Actually, if we define gamuts as not just an array, but an array of Object values (with suitable defaultKey/defaultValue) this should be fixed automatically, since objects are compared by calling equals() recursively. Whereas now there is no type for array values, so it falls back to the default equals.

This is also a Nude Element issue, since there's no way to do that (typeOptions only goes one level down, so we can do itemType: Object, but then we can't set any typeOptions for said type. So it will require a reworking of that part of the API.

DmitrySharabin commented 3 months ago

Ah, so gamut depends on this.gamutInfo.id, but because the object this.gamutInfo didn't change, NudeElement doesn’t realize its property may have changed, right?

Just making sure I got it right before suggesting solutions.

this.gamutInfo did change (at least, its label property), and NudeElement noticed it. This change launched the update of gamut. But since this.gamutInfo.id didn't change, technically, gamut's new and old values are the same. So, NudeElement stopped propagating changes.

DmitrySharabin commented 3 months ago

This is also a Nude Element issue, since there's no way to do that (typeOptions only goes one level down, so we can do itemType: Object, but then we can't set any typeOptions for said type. So it will require a reworking of that part of the API.

I was going to request this feature on NudeElement later today. Yesterday, I was trying to describe gamuts as an array of objects, but we don't support it yet. If we have it one day, this will be awesome!

LeaVerou commented 3 months ago

This is also a Nude Element issue, since there's no way to do that (typeOptions only goes one level down, so we can do itemType: Object, but then we can't set any typeOptions for said type. So it will require a reworking of that part of the API.

I was going to request this feature on NudeElement later today. Yesterday, I was trying to describe gamuts as an array of objects, but we don't support it yet. If we have it one day, this will be awesome!

We do support it, we just don't support customizing that Object type in anyway, so it's almost useless.

DmitrySharabin commented 3 months ago

Since all code inside the block depends only on gamutInfo, I would change the condition to name === "gamutInfo". I like this fix better—it sounds more logical to me.