How to use spies

35 views
Skip to first unread message

Antonio Calanducci

unread,
Jan 25, 2014, 5:18:27 AM1/25/14
to tish...@googlegroups.com
Hi,

I am not able to let spies work.
According to the documentation, I add a spy to any object first. For example:

//addSpy("warningLabel",warningLabel)
var warningLabel = Ti.UI.createLabel({
top: "10dp",
text: "ATTENZIONE: il cambio password è valido solo per le utenze NON associate a personale RaM",
color: "white",
textAlign: "center",
font: {
fontWeight: "bold",
fontSize: "16dp"
}
});

than I use tishadow repl on the same project and from the repl I run:

> wlabel = getSpy("warningLabel");

> [REPL] [iphone, 7.0, 192.168.0.101] 

So in principle I should be able to change any property on my label using:

> wlabel.text = "ciao"

But for any property or method I invoke on wlabel, I alway get that is an undefined object:

> [ERROR] [iphone, 7.0, 192.168.0.101] TypeError: 'undefined' is not an object (evaluating 'wlabel.text = "ciao"')


One annoying thing on the REPL is that I don't get always the prompt ready. I need to type some text, than press enter and then use the arrow up cursor to show it up.

Anyway has been able to use spies?

Am I doing something wrong?

thanks
Antonio


David Bankier

unread,
Jan 25, 2014, 6:18:01 PM1/25/14
to Antonio Calanducci, tish...@googlegroups.com
Are you using Alloy? If so, comments are stripped out.

David

Antonio Calanducci

unread,
Jan 25, 2014, 6:28:19 PM1/25/14
to tish...@googlegroups.com
Nope, using it in classic mode. What should I check?

David Bankier

unread,
Jan 25, 2014, 6:35:40 PM1/25/14
to Antonio Calanducci, tish...@googlegroups.com

Yes sorry. Just use it without the commenting out. I'll update the docs.

Antonio Calanducci

unread,
Jan 25, 2014, 6:38:53 PM1/25/14
to tish...@googlegroups.com
Thx, i will test it out tomorrow.
In the doc, anyway, you mention spies support for alloy too. Is this still valid? How to use them 4 alloy?

David Bankier

unread,
Jan 25, 2014, 6:42:53 PM1/25/14
to Antonio Calanducci, tish...@googlegroups.com
Same way. Here is alloy.jmk file I wrote a while back that automatically injects spy to each of the controllers and removes them post compile: https://gist.github.com/dbankier/5648950

Antonio Calanducci

unread,
Jan 26, 2014, 11:12:18 AM1/26/14
to tish...@googlegroups.com, Antonio Calanducci
Hi David,

I have tested your suggestions. Thank you. Here some comments:

- as suggested, spies in classical titanium, work, as suggested, without the the comment syntax. Anyway, at the beginning I was not able to let them work, because I was adding the addSpy call, BEFORE the object I want to spy, and for some reason this doesn't work. The spy works only if you declare AFTER the object you want to attach too. I don't know if this is a bug or how it should work, but from the docs, the // notations let me think to "annotation" or "decorator" of other programming language and framework, so I was natural to me to add it before. Anyway, using the // notation would be useful if after testing you would to deploy you don't need to manually remove all the spies in your files before deployment

- I have also tested out your alloy.jmk to tries spies in Alloy. I works well if you are manually pushing updates with ts run -u, but if you are going to use ts @ run -u, the tishadow server starts an infinite loop (cause controller files change during the pre:compiler task, when you inject the spy at the end of the file). Probably if one uses spies doesn't need too much the autoreload features, so we can live with this, but if you find a way to fix this, it would be great. 
Anyway, can I always manually add the spy at the end of each controller with addSpy("controller_name", $) ? am I correct?

Thank you
Antonio
Reply all
Reply to author
Forward
0 new messages