Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#1581 closed enhancement (invalid)

isSet(property) reflection method

Reported by: ole_ersoy@… Owned by: tk
Priority: high Milestone: 0.9
Component: General Version: 0.3
Keywords: Cc: ole_ersoy@…, ktiedt@…
Blocked By: Blocking:

Description

Could we put a

dojo.lang.isSet(property)

method in dojo.lang

?

that works like this:

function isSet(property) {

if (property == ) {

return false;

}

}

Change History (9)

comment:1 Changed 13 years ago by dylan

Milestone: 0.5
Owner: changed from anonymous to tk

comment:2 Changed 13 years ago by guest

ooops,

It's supposed to be

if (property == ) { return false}

comment:3 Changed 13 years ago by tk

Cc: ole_ersoy@… ktiedt@… added
Status: newassigned

What are you checking for the property of?

If an object.... check dojo.lang.has(object, "property"); Otherwise... are you asking for a way to test variables set/null/undefined?

comment:4 Changed 13 years ago by joose@…

this kind of function can not be created with javascript.

Why?

Because myFunction(property) will not work if property is not defined.

So what will work then?

  if (typeof(property) == "undefined") { ... }

comment:5 Changed 13 years ago by ole_ersoy@…

Hmm,

Good point.

The property does need to be defined.

I'm using isSet() within the dojo.presentation framework as a way to communicate whether a property has been set or not.

So a component has properties that are declared using dojo.declare().

The definition within the dojo.presentation of an unset property is

UN_SET_PROPERTY: "".

So we could add:

if ( typeof( property == 'undefined' ) { throw new Error("The property must be created before the isSet method can be used.") }

I think a isDefined() or exists() method should be substituted for

property == 'undefined'

so function isDefined(property) {

if (property == 'undefined') return false;

}

So to summarize: isSet assumes the property exists and that the unset value is .

isDefined / exists() checks whether the property exists to start with.

wdyt?

comment:6 Changed 13 years ago by ole_ersoy@…

Incidentally - I'm aiming for a reflective method similar to the one used in the Eclipse EMF API on the EObject:

Here's the API Description:

(EStructuralFeature in Javascript would be either an Object reference or a primitive like String)

eIsSet

public boolean eIsSet(EStructuralFeature feature)

Returns whether the feature of the object is considered to be set.

If the feature is many-valued, the value must be an EList and the feature is considered set if the list is not empty. If the feature is unsettable, the modeled state is directly available and is used. Otherwise, the unresolved value of the feature of the object is compared against the feature's default value or the meta class's default value, as appropriate; the feature is considered set if it's not the same as the default.

This property can affect serialization, since defaults are typically omitted in a compact serialization.

Parameters:

feature - the feature in question.

Returns:

whether the feature of the object is set.

Throws:

IllegalArgumentException? - if the feature is not one the meta class's features.

See Also:

eSet(EStructuralFeature, Object), eUnset(EStructuralFeature), eGet(EStructuralFeature, boolean)

Slightly OT:

Since one of the goals of dojo.presentation is also to handle dojo.presentation.application.Application client side persistence, I'll be using the EMF API as a baseline for some of the reflective features used in the dojo.presentation API.

Right now isSet lives in dojo.presentation.reflection.

So if we agree on what isSet, etc. means hopefully the methods can find a home a home in dojo.lang...

comment:7 Changed 13 years ago by tk

You description sounds conveniently similiar to dojo.lang.has(obj,prop)....

comment:8 Changed 13 years ago by ole_ersoy@…

Hmmm - I just looked at it:

dojo.lang.has = function(obj, name){

try{

return (typeof obj[name] != "undefined");

}catch(e){ return false; }

}

So I get true if it's not 'undefined'

I want true if it's not "".

I think that's an important difference.

I also noticed that there is a isUndefined method...

which would satisfy the exists() part discussed.

So when I use isSet(property) I know that the property exists already/should exist. I just want to know whether someone configured it, or whether it is set to the "UN_SET" value.

If I use dojo.lang.has(), it should always return true.

comment:9 Changed 13 years ago by tk

Resolution: invalid
Status: assignedclosed

Recommended to close this, so doing so.

Note: See TracTickets for help on using tickets.