Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

returnType ignored by some fatories #9

Open
sukima opened this issue Dec 10, 2013 · 1 comment
Open

returnType ignored by some fatories #9

sukima opened this issue Dec 10, 2013 · 1 comment

Comments

@sukima
Copy link

sukima commented Dec 10, 2013

I found two cases where the return value from a factory does not match the returnType defined in the supplied api.jsca.

Of note Ti.Database.open does not return a Ti.Database.DB object. To test see if the object returned has anexecute()` method.

Ti.UI.iOS.createToolbar does not return a Ti.UI.iOS.Toolbar object. I found it is missing the show() and hide() methods inherited from Ti.UI.View.

Is it possible that the returnType in the api.jsca is being ignored? I eventually had to polyfill my methods:

global.Ti.UI.iOS.createToolbar = (props) ->
    toolbar = {}
    toolbar[key] = val for key,val of Ti.UI.iOS.Toolbar
    toolbar[key] = val for key,val of props
    toolbar

In JS:

global.Ti.UI.iOS.createToolbar = function(props) {
  var key, toolbar, val, _ref;
  toolbar = {};
  _ref = Ti.UI.iOS.Toolbar;
  for (key in _ref) {
    val = _ref[key];
    toolbar[key] = val;
  }
  for (key in props) {
    val = props[key];
    toolbar[key] = val;
  }
  return toolbar;
};
@sukima
Copy link
Author

sukima commented Dec 10, 2013

If I find I do this often I'll use a pollyfill function:

pollyfillTi = (returnType) -> (props) ->
  retObj = {}
  retObj[key] = val for key,val of returnType
  retObj[key] = val for key,val of props
  retObj

global.Ti.UI.iOS.createToolbar = pollyfillTi(Ti.UI.iOS.Toolbar)
function pollyfillTi(returnType) {
  return function(props) {
    var key, retObj, val;
    retObj = {};
    for (key in returnType) {
      val = returnType[key];
      retObj[key] = val;
    }
    for (key in props) {
      val = props[key];
      retObj[key] = val;
    }
    return retObj;
  };
};

global.Ti.UI.iOS.createToolbar = pollyfillTi(Ti.UI.iOS.Toolbar);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant