Fork me on GitHub
#reagent
<
2015-10-25
>
manutter5117:10:30

Is there a trick to getting style changes to show up in reagent? I built a cool little “Dynamic CSS” mockup for a project at work that sets the :style directly on individual elements based on @app-state, and now I want to build a non-work-specific demo, but the styles aren’t updating.

manutter5117:10:06

My presentation is this coming Tuesday 😕

manutter5117:10:56

I just now pushed an update to the refactor2 branch with some data-foo attributes on the header component, for debugging

manutter5117:10:23

My color changes propagate to the data-foo elements, but the style attribute on the page is stuck with the original colors.

manutter5117:10:51

Tested on 2 different machines, same behavior

mikethompson22:10:12

@manutter51: happy to help, but you'll need to make it a bit easier for us. You've branch has a lot of code in it. What exactly is the problem and where?

manutter5122:10:38

Awesome, thanks

manutter5122:10:56

The code I’m working on is the header component

manutter5122:10:30

starts around line 38 of mock-css/core.cljs

gadfly36122:10:44

Firsy thing i see is derefs above an inner anonymous function

gadfly36122:10:57

Those will only get derefed once because not in render phase

manutter5122:10:33

I moved them there in the process of trying to figure stuff out

mikethompson22:10:48

@gadfly361: those derefs are in functions, so it depends when they are called

manutter5122:10:05

what I’m seeing is that the data-bg-color attributes are updating, but the style is not

manutter5122:10:25

(I’m using the “tweak” fn to update the app-state at the repl)

gadfly36122:10:43

Ahh didnt look closely enough, youre right @mikethompson

manutter5123:10:18

So for example, I call (tweak :primary-bg-color “red”) and I can see :data-row-style update to “red” but :style stays at the original color.

mikethompson23:10:28

Note: background-colour is the way you write styles in reagent, rather than backgroundColour

manutter5123:10:53

Ok, that’s how I had them originally, but that wasn’t working so I tried it the react way

mikethompson23:10:10

Yep, I don't think that will be a problem, but just noting

mikethompson23:10:45

After line 52, tuck this just inside your outside header [:div [:pre (pr-str (row-style))]

manutter5123:10:48

just btw for the Tuesday demo I’ve thrown together a simpler ToDoMVC-ish project to use as Plan B

mikethompson23:10:07

That will allow you to see in rendered

manutter5123:10:30

so this is something I’d like to solve, but if I don’t, no biggie

manutter5123:10:02

I can see the results of (row-style) in the REPL, it’s returning the correct HTML with the updated style attributes

manutter5123:10:31

but when I use dev tools to inspect the element on the page, it shows the data-row-style attribute as updated, but the style attribute is unchanged.

manutter5123:10:03

I also see console log messages saying that the functions are being called like I expect.

mikethompson23:10:41

I can't see a reason for that not working

manutter5123:10:51

That makes me feel better about my sanity simple_smile

manutter5123:10:17

I have code that is very much like that in the mockup I made for work, and it’s working perfectly, styles update no problem.

manutter5123:10:09

I just fired it up again and ran (tweak :primary-bg-color “red”) which should change the header div to “red !important” as the background-color, but instead I get this: <div class="col-xs-12 header-panel" data-panel-style="{:backgroundImage &quot;url(\&quot;img/kids-racing.png\&quot;)&quot;, :backgroundColor &quot;red !important&quot;}” style="background-image:url(&quot;img/kids-racing.png&quot;);background-color:#37441e !important;" data-reactid=".0.0.0.0">

manutter5123:10:37

data-panel-style is showing a string dump of the results of the function call, and contains backgroundColor “red !important” as expected, but style still has background-color:#37441e

eggsyntax23:10:44

@manutter51: Just to be sure, have you tried doing a clean and rebuild (of both the clj and cljs)? I find that really odd inconsistencies can occasionally be solved that way (because eg stale JS).

manutter5123:10:32

Yeah, I’ve even gone as far as re-installing Node, deleting the target directory completely, deleting node_modules completely, even rebooting

manutter5123:10:51

Ok, I'm going to chalk this one up to the gods of mayhem, and just go with the ToDoMVC demo. No doubt the issue will spontaneously resolve itself on Wednesday.

manutter5123:10:02

Thanks for the input everyone.