11

Application

  1. Root
    1. Once
      1. Application

An Application class has only one instance. An Application instance can have a name. It can be associated to another instance which will interpret all the messages it receives but which it doesn't implement.

INSTANCE METHODS

  1. import { defclass, sendmsg, supersend } from 'So-o';
  2.  
  3. import 'Once';
  4.  
  5. defclass('Application', Once, 1,
  6.     null,
  7.     ['appName', 'app'],
  8.     null,

The Application class inherits from the Once class. The instance properties appName and app contain the name of an Application instance and the reference to its proxy. The Application class redefines the instance messages init and doesNotRecognize. It adds the instance message appName.

init
SYNOPSIS

sendmsg($self, 'init', appName = null, app = null)

DESCRIPTION

init initializes the name and the proxy of self with appName and app.

CODE
  1.     {   'init':
  2.             (self, appName = null, app = null) => {
  3.                 supersend(Application, self, 'init');
  4.  
  5.                 if (appName) {
  6.                     sendmsg(self, 'set', 'appName', appName);
  7.                    
  8.                     if (app)
  9.                         sendmsg(self, 'set', 'app', app);
  10.                 }
  11.                
  12.                 return self;
  13.             },

Runs the init method of the superclass of the Application class. Initializes the instance properties appName and app with the parameters appName and app.

appName
SYNOPSIS

sendmsg(self, 'appName')

DESCRIPTION

appName returns the name of the Application instance self. If self has no name, appName returns null.

CODE
  1.         'appName':  (self) => sendmsg(self, 'get', 'appName'),

Returns the appName property of self.

doesNotRecognize
SYNOPSIS

sendmsg(self, 'doesNotRecognize', msg[, arg...])

DESCRIPTION

An Application instance intercepts the message doesNotRecognize which is automatically sent to a class or an instance which receives a message it doesn't implement.

doesNotRecognize returns the result of forwarding msg and its parameters to the proxy of self, the instance which was passed as a parameter to the new message to create self.

If self has no proxy, doesNotRecognize executes the message doesNotRecognize in the context of the superclass of the Application class, which will run the doesNotRecognize method of the Root class, which displays an error message.

CODE
  1.         'doesNotRecognize':
  2.             (self, msg, ...args) => {
  3.                 let app = sendmsg(self, 'get', 'app');
  4.  
  5.                 if (!app)
  6.                     return supersend(Application, self, 'doesNotRecognize', msg);
  7.  
  8.                 return sendmsg(app, 'perform', msg, args);
  9.             }
  10.     }
  11. );

Initializes app to the value of the app property of self. If app is null, returns the result of executing the message doesNotRecognize by the superclass of the Application class. Otherwise, if self has a proxy, returns the result of sending msg and its parameters to app.

EXAMPLE
  1. import { sendmsg } from 'So-o';
  2.  
  3. import 'Hello';
  4.  
  5. var hello = sendmsg(Hello, 'new');
  6.  
  7. sendmsg(hello, 'hello');

Creates an instance of Hello and sends it the message hello.

  1. import 'Application';
  2.  
  3. var app = sendmsg(Application, 'new', 'Hello', hello);
  4.  
  5. console.log(sendmsg(app, 'appName'));

Creates an instance of Application called Hello with hello as proxy. Displays its name.

  1. sendmsg(app, 'hello');

Sends the message hello to app which forwards to hello.

  1. sendmsg(app, 'foobar');

Sends to app a message unknown to the proxy.

  1. sendmsg(app, 'set', 'app', null);
  2. sendmsg(app, 'hello');

Removes the proxy from app and sends the message hello to app.

$ ln Hello.js node_modules/Hello.mjs
$ ln testApplication.js testApplication.mjs
$ nodejs --experimental-modules testApplication
Hello from So-o!
Hello
Hello from So-o!
Hello::foobar Invalid instance message
Application::hello Invalid instance message
SEE ALSO

Once, Responder

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].