Easy API Mapping concept

# memolus at googlemail.com (16 years ago)

This is my idea for an easy mapping concept:

First Example:

this.__defineGetter__("modus", function() {
	return !gui.hidden;
});
this.__defineSetter__("modus", function(modus) {
	return gui.hidden = !modus;
});

will be turned into:

this.modus := function() { return !gui.hidden }

Second Example:

this.__defineGetter__("input", function() {
	if (modus === true)
		return gui.input;
	else
		return gui.placeholder_input;
});
this.__defineSetter__("input", function(input) {
	if (modus === true)
		return gui.input = input;
	else
		return gui.placeholder_input = input;
});

will be turned into:

this.input := function() {
	if (modus === true)
		return gui.input;
	else
		return gui.placeholder_input;
}

Third Example:

this.__defineGetter__("name", function() {
	return "Bob";
});
this.__defineSetter__("name", function(newName) {
	return "Bob"; // ignore newName
});

will be turned into

this.name := function() { return "Bob"; }

There also be the easier way:

this.name := "Bob";

You could also write:

let name = "Bob"; this.name := name;

Note that this.name := firstname + surname; and this.name := function() { return firstname + sirname; } are NOT equivalent. In the first example the operator will be executed one time when the interpreter reads this line, in the second example the function will always be called if you want to get or set this.name. Note that 'this.name' and 'this.name="abc"' are equivalent after you wrote the mentionend line. This is only a side-effect. The real features are "dynamic references" and "references to primitive data types".

dynamic references: You can get another reference each time you get or set the object

references to primitive data types: You can set an real reference to a String or a Number

These are all features important to API mapping.

# Mike Samuel (16 years ago)

2009/12/27 memolus at googlemail.com <memolus at googlemail.com>:

This is my idea for an easy mapping concept:

First Example:

this.defineGetter("modus", function() {                return !gui.hidden;        });        this.defineSetter("modus", function(modus) {                return gui.hidden = !modus;        });

will be turned into:

this.modus := function() { return !gui.hidden }

Second Example:

this.defineGetter("input", function() {                if (modus === true)

Is modus a global variable or does it bear any relation to this.modus defined above?

return gui.input;                else                        return gui.placeholder_input;        });        this.defineSetter("input", function(input) {                if (modus === true)                        return gui.input = input;                else                        return gui.placeholder_input = input;        });

will be turned into:

this.input := function() {                if (modus === true)                        return gui.input;                else                        return gui.placeholder_input;        }

Third Example:

this.defineGetter("name", function() {                return "Bob";        });        this.defineSetter("name", function(newName) {                return "Bob"; // ignore newName        });

will be turned into

this.name := function() { return "Bob"; }

There also be the easier way:

this.name := "Bob";

You could also write:

let name = "Bob"; this.name := name;

Note that        this.name := firstname + surname; and        this.name := function() { return firstname + sirname; } are NOT equivalent. In the first example the operator will be executed one time when the interpreter reads this line, in the second example the function will always be called if you want to get or set this.name. Note that 'this.name' and 'this.name="abc"' are equivalent after you wrote the mentionend line. This is only a side-effect. The real features are "dynamic references" and "references to primitive data types".

dynamic references:        You can get another reference each time you get or set the object

references to primitive data types:        You can set an real reference to a String or a Number

These are all features important to API mapping.

Can't they be achieved with a library function mapApi(xform, source, sourcePropertyName, target, targetPropertyName) ?

# memolus at googlemail.com (16 years ago)

Mike Samuel <mikesamuel at gmail.com> wrote:

Is modus a global variable or does it bear any relation to this.modus defined above?

It's an boolean. So it could be this.modus.

Can't they be achieved with a library function mapApi(xform, source, sourcePropertyName, target, targetPropertyName)

No. It does not work with private objects and with dynamic references. Can you explain what you mean with xForm? Is it sth like my function which chooses the reference each time you access the object? My concept covers multiple targets.

You would need such an library function: mapApi(ChooseTarget, source, sourcePropertyName, target1, targetPropertyName1, target2, targetPropertyName2, target3, targetPropertyName3)

For private objects you would have to use (in order to have a property of a source):

var priv = { title:null }

Example function for ChooseTarget:

function() { if(modus===true) return 1; else return 2 }

It's ugly.

# Mike Samuel (16 years ago)

2009/12/27 memolus at googlemail.com <memolus at googlemail.com>:

Mike Samuel <mikesamuel at gmail.com> wrote:

Is modus a global variable or does it bear any relation to this.modus defined above? It's an boolean. So it could be this.modus.

Right now it looks like a reference to a global variable since there is no local variable or parameter of that name.

Can't they be achieved with a library function mapApi(xform, source, sourcePropertyName, target, targetPropertyName) No. It does not work with private objects and with dynamic references. Can you explain what you mean with xForm? Is it sth like my function which chooses the reference each time you access the object? My concept covers multiple targets.

xform would be a transform which converts from the source form to the target form and back.

You would need such an library function:  mapApi(ChooseTarget, source, sourcePropertyName, target1, targetPropertyName1, target2, targetPropertyName2, target3, targetPropertyName3)

Isn't that trivial to implement on top of a single property mapping function?

For private objects you would have to use (in order to have a property of a source):

What is a private object?