macMikey / LCB-missing-manual

I'm trying to learn LCB, again, but the docs are thin.
MIT License
4 stars 4 forks source link

what comes first, OnLoad() or OnCreate() #16

Closed macMikey closed 1 year ago

macMikey commented 1 year ago

I would guess OnLoad() since it is responsible for grabbing all the saved properties and defaults, but it's not clear.

bwmilby commented 1 year ago

OnCreate happens first - this is what initially sets up the widget and loads the defaults. Once that is done, OnLoad will pull in the saved settings.

If keys are absent from the property array, do not set them to default values. Rely on the onCreate() handler to have already done that.

macMikey commented 1 year ago

the comment that you pasted about relying on the onCreate() handler - where did you get that? when i looked in the navbar code, the defaults are set in the onLoad() handler

bwmilby commented 1 year ago

That one was from the style guide.

That's not what I see in the version that I have downloaded. OnLoad is pulling in properties and setting them, but the defaults are in the OnCreate handler.

macMikey commented 1 year ago

Maybe we're not talking about the same thing for defaults. What do you mean by defaults? All I see being set in OnCreate are the buttons for the original navbar. I guess I'm wondering why those would be set in there, if it's earlier, because when I look at OnLoad() I see a bunch of prop "defaults" (I guess) set like this

if "showBorder" is among the keys of pProperties then
        put pProperties["showBorder"] into mShowDivide
    else
        put true into mShowDivide
    end if
bwmilby commented 1 year ago

Ok, I missed that. Those else clauses are not needed and shouldn't be there. If you look at the TreeView widget you will see that it does not have the extra else clauses in the OnLoad handler.

macMikey commented 1 year ago

I'm assuming you wrote TreeView, right? in cases where you have, for example if "alternate row backgrounds" is among the keys of pProperties then what do you do if there is no key? also, the style guide says that you should use property setters, and not touch the internal vars, but obviously you are doing that. i'm more inclined to do what you did: skip all the cleansing input overhead. thoughts?

bwmilby commented 1 year ago

I didn't write it, but fixed some bugs and extended it a bit. If there is no key, then the default value is retained. This is useful for when new properties are added. The are set in OnCreate and then updated in OnLoad so if anything is missing it just keeps the default value. I never noticed the getter/setter comment in the style guide until recently. I think it is probably more related to other actions that need to happen when setting a property. graph.lcb does use setters for many properties. navbar.lcb does it for a couple - one is used to adjust from a previous way of setting that particular property. TreeView does use it for one - setArrayData

BerndN commented 1 year ago

if "showBorder" is among the keys of pProperties then put pProperties["showBorder"] into mShowDivide else put true into mShowDivide end if

As I understand the else it comes from adding a property in a later version and prior versions stored properties dont have that new property saved. That is the reason for the else clause. It is actually only needed the first time the new properties are loaded since they are saved in onSave.

macMikey commented 1 year ago

Ali discusses this very topic during one of his LCB Sessions around the 8:38 mark