PDA

View Full Version : State.manager default value


tryanDLS
10-27-2006, 12:39 PM
Jack,

Something you might consider adding to the get() for State.manager so client code doesn't always have to check for a missing value. This could streamline code alot in cases where there's a bunch of 1st time setup.

get: function(key, defValue) {
var val = provider.get(key);
if (typeof val == 'undefined' && defValue) {
val = defValue;
provider.set(key, defValue);
}
return val;
},

Tim

jack.slocum
10-27-2006, 01:19 PM
It's in the current beta. I ran into the same thing when I was making state handling automatic for BorderLayout so I added it. :)

One difference though, I don't set the defaultValue, I just return it. Is there a reason why you think the default value should be persisted? I can add it if it makes sense.

tryanDLS
10-27-2006, 01:32 PM
Maybe not that big a deal, except if you had something tied to a statechange event. if client code was
initially something like:
var x = get ('x');
if (!x) {
x = set('x', 1); // this trigers something on statechange
}

var x = get('x', 1); // this should do the same thing.

I don't necessarily have anything that would use this functionality, but since the event's there... :)

tryanDLS
10-27-2006, 01:43 PM
That previous code should just be:

f (!x) {
set('x', 1); // this triggers something on statechange
}

wasn't implying that set should be changed to return a value.

On another note, I know it's beta, but are you aware that the comments view in forum2 no longer scrolls vertically (at least in FF).

Also, I sent you an email yesterday, just wanted to verify that it got to you since my wireless is acting up. If you just haven't responded yet, it's not critical, but if you didn't get it, I'll resend.

jack.slocum
10-27-2006, 02:24 PM
My thought was that if it's never explicitly set (the state value) then later you change the default value and the user would get the new default value. Also, it saves cycles since you aren't restoring a value that was never actually set.

But the event that you mentioned is a good point. I can see where you would want to do both. Like the default size for X column is 200 and you call get() with a defaultValue (200) you don't want to trigger an event that would cause the UI to be recalculated since it's already 200. At the same time there are plenty of instances where you would probably want the event to automatically fire. Maybe the solution is a 3rd boolean param whether to set it in the state if it's the default.

I did get your email. Unfortunately Yahoo Mail converted the attachment to inline and I can't scroll the window now (probably because of the style "body{ overflow:hidden}" in the HTML file). Very dumb Yahoo! Anyway, I am hoping the new release will fix many of your problems. It will be up for download in a little bit.

tryanDLS
10-27-2006, 03:35 PM
I'd agree with the idea of a bool. I think as the UI gets more complex, any opportunity to short circuit unnecessary events is a good thing.

I'll wait for the next code drop and send a zip if I still run into problems.