× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Debugging Announcement issues in Amber

Sebastian Sastre
Jan 27, 2015
<p>Using an <code>Announcer</code> can give you a lot of flexibility for making your Amber components interact loosely coupled.</p> <p>And while developing, is normal to rename a class. </p> <p>Today I've was working with a product and I had this announcement class with a typo <code>OrdedProductEditRejected</code> which I've renamed to <code>OrderedProductEditRejected</code>.</p> <p>None of the current Amber IDE's have a refactoring tool to help you to rename globally and changing the methods that are using the class, so you have to go old school and rename in every place yourself.</p> <p>So far so good. Until you forget to rename it in one method and your app uses that.</p> <p>What happens in the method using the old name, is that you get <code>nil</code> there and the announcer will throw an exception (<code>nil does not understand #name</code>).</p> <p>Trying to find references of the class doesn't work anymore because it already has the new name. And if you forgot the exact previous name, the search for references will not help.</p> <p>So what do you do!?</p> <p>In flow based applications, the <code>App</code> class implements <code>on:do:</code> in this way:</p> <p><code>App&gt;&gt;on: ann do: aBlock</code></p> <p><code>  self announcer on: ann do: aBlock</code></p> <p>So every time your code subscribes to observe an event it will send that message. Knowing that, you can debug this kind of problem by setting a <code>halt</code> so when the announcement class is nil it stops and you know what to fix.</p> <p>This is how it looks:</p> <p><code>App&gt;&gt;on: ann do: aBlock</code></p> <p><code>  ann ifNil: [ self halt ].</code></p> <p><code>  self announcer on: ann do: aBlock</code></p> <p>With that, you use your application and when it halts, you'll see in the debugger's stack the sender you forgot to correct.</p> <p> </p>
comments powered by Disqus