Skip to content
mkroehnert edited this page Mar 10, 2013 · 43 revisions

How do I extend core classes?

If you wish to extend core Amber classes with extra methods, and commit those changes without overwriting the Kernel-Objects.js file (for example), you must set a "Method Protocol" for the method and enter the protocol of "*MyPackage" where "MyPackage" is the package you want to commit that method to. This is exactly like "class extensions" in Monticello in Pharo/Squeak etc and makes sure that the method belongs in the MyPackage package and not in the package of the extended class.

The Method Protocol drop-down

How to insert raw html?

You have to use JQuery for doing that:

html p asJQuery html: '<p>hello world</p>'

How can I insert link in the produced html?

Following the Seaside convention: html p with: [ html a href: 'http://www.google.fr'; with: 'Google']

How can I fire and receive events?

Events are fired and consumed in Amber via the "Announcements" system. To use announcements, first you need an instance of Announcer. There is already a SystemAnnouncer for example, which can be obtained through:

announcerInstance := SystemAnnouncer current.

You can also create your own single instance of Announcer or a subclass of it.

Then you need a class for each announcement (see SystemAnnouncement and subclasses). Announcement classes don't necessarily need any methods.

Sending announcements is as easy as:

announcerInstance announce: AnnouncementClass new.

For receiving announcements you have to register a callback for the desired announcement class like the following:

announcerInstance on: AnnouncementClass do: [:announcement | "do something when announcement occurs"].

How can I access Smalltalk members in inline JavaScript?

All Smalltalk instance variables can be accessed as JavaScript properties by adding an @ sign in front of their name. For example, to access the counter variable of class Counter you would do the following:

Counter>>assignTwo
    < self[ "@counter" ] = 2; >

Clone this wiki locally