ngageoint / endpoint.js

Web application discovery, execution and streaming library
http://ngageoint.github.io/endpoint.js/
Apache License 2.0
26 stars 5 forks source link

Facade (onReady) and getApi() syntax is clunky #5

Open datasedai opened 8 years ago

datasedai commented 8 years ago

Using facades is a bit clunky, it could be cleaned up.

For instance, when a facade is ready, you have this code here:

var facade = endpoint.createFacade(...);
facade.on('ready', function() {
  api = facade.getApi();
  api.callFunction();
});

It would be nicer if we could do something like this:

var facade = endpoint.createFacade(...)
.then(function(api) {
  api.callFunction();
  // don't want it to get confusing here, because some people might try to do 'return api.callFunction()' but we're not in a strategy right now, we're just in a kinda onReady function...
});

This way it would kinda look like what it looks like when you're using the facade to call functions.

This would be harder to do for child facades:

api.callFunction().facade()
.then(function(childFacade) {
  var childApi = childFacade.getApi()
});

The above is kinda clunky. It would be nice if we could get the API right away, then call child functions...

var childFacade = api.callFunction().facade()
.then(function(childApi) {
  childApi.callFunction();
  // don't want it to get confusing here, because some people might try to do 'return api.callFunction()' but we're not in a strategy right now, we're just in a kinda onReady function...
});

Maybe this could work. Needs to be thought out more.

datasedai commented 8 years ago

After working with some folks to try to help them integrate with Endpoint.js, I think it would make more sense to remove the .facade() syntax; instead, if the returning object has any 'function' property at all (or a prototype), then just return it as a facade type.

To mitigate getting properties off the object, we can use a '.getProperties()' function on the facade, which will execute like a strategy function and return facades or json/primitives.

This should tie in to the solution to #4

As an alternative, the strategy can have 'returnAsFacade()' or 'returnAsObject()' to override the automatic behavior (for performance) when desired.

datasedai commented 8 years ago

Added wiki.