CodeParadise is the name of a framework and a future platform. CodeParadise as framework allows developing web applications, Node.js applications and mobile apps in Smalltalk only. CodeParadise is based on the Pharo Smalltalk environment.
The general principle behind CodeParadise is the execution of a regular (but tiny) Smalltalk image inside a JavaScript execution environment. During development this tiny Smalltalk image communicates with a full Pharo development environment to be kept up to date and provide the typical live programming experience we love so much in Smalltalk. Since CodeParadise runs in a Smalltalk image, there is no need for transpiling Smalltalk to JavaScript. That is: Smalltalk all the way!
JavaScript libraries can be used from your Smalltalk code quite easily. The DOM model is coded in CodeParadise, but many other things can be accessed through a generic proxy mechanism. Furthermore, support has been added for two UI frameworks:
A few online videos:
See introduction for a more thorough explanation of CodeParadise as the future platform.
Relevant documentation:
Currently CodeParadise can only be used in a Pharo environment. In the future other Smalltalk environments like Cuis might be supported as well.
Getting started requires a few simple steps:
Loading CodeParadise can be done using:
Metacello new
repository: 'github://ErikOnBike/CodeParadise';
baseline: 'CodeParadise';
load.
If you plan on developing Node.js applications, please clone the CP-Node repo into a separate directory. It only contains 2 'required' files: cp-node.js and client-environment.image. You can also copy them to a preferred directory (instead of cloning the repo).
Thanks to Tim there is a menu 'Paradise' in Pharo's menubar which allows starting the environment. First select 'Reset' from the 'Paradise' menu and then open one of the existing web applications through 'Open'. Some more explanation follows below for manually starting and stopping servers and applications.
If all went well you should be able to fire up a number of browser tabs/pages and start using the example applications. Profit warning: the examples are still very limited, but should allow some insight in what is possible and allow you to play with it yourself.
The example applications can be reached using the following URLs:
A bigger example application is under development. It is a Zettelkasten application.
To start a Node.js application, execute the following from a CP-Node directory:
APP="http-server-example" SERVER_URL="ws://localhost:8080/io" node cp-node.js client-environment.image
(replace the value of the APP environment variable with the identifier of your preferred application)
The Ionic Framework support is a recently added feature. It allows you to build mobile apps more easily.
If you are using Ionic components inside your shadow DOM (the recommended way when creating WebComponents with CodeParadise), please make sure to include the CSS bundle in all your #style methods. Ionic uses some global styling which does not penetrate through the shadow DOM's encapsulation. Please add the following CSS rule to your style method (or use a more specific version if required):
@import url("https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css");
The CSS included is not very big in size and browsers should cache the content, so it does not have to load on every WebComponent you have developed.
CodeParadise currently has a 'debugger' and a View inspector. The debugger is mostly an inspector too, you can't change code but you can see the stack trace and inspect variables. Already very useful during development.
The View inspector allows you to open a special pane in which you can view the DOM, including the Shadow DOM of your WebComponents. The WebComponents created in Smalltalk can be edited right in your browser! Change the HTML template or CSS style of your WebComponent in two coding panes. Update the browser by simplying pressing Cmd-S/Ctrl-S or clicking a button. Press Shift-Cmd-S/Shift-Ctrl-S to actually save it in your Smalltalk image once your satisfied with the results. To start the View inspector press Cmd-i/Ctrl-i or press Cmd-b/Ctrl-b to select a WebComponent by name (instead of browsing through the DOM).
You can install the debugger or View inspector sending either addDebugger
or addViewInspector
to your Application (in the load
method of the Application for example).
To start CodeParadise the following code has to be executed:
CpDevTools start.
This will start a HTTP and WebSocket server. Once the environment is started you can run as many applications as you want. You can then start an application using the following:
CpPresentationWebApplication openInBrowser.
When you are done or want to reset the environment, the following code can be executed:
CpDevTools stop.
"Garbage collect works better in triples ;-)"
3 timesRepeat: [ Smalltalk garbageCollect ].
Tip: The server image keeps all sessions in memory at the moment (they never expire yet). So once in a while use the reset code above to clean up the sessions. Remember the sessions will also be saved in the image. So closing and reopening your image should bring you back the session and you can continu where you left off.
If you encounter any problems with connecting to the server, please check that no other web server is running on the port you are using/trying to use. If you have started a web server pointing to the wrong client environment, please first stop that instance. Otherwise you will keep on serving files from an empty or non-existing directory. Use the reset as described above to stop the server. You might want to check if all ZnServer instances are really stopped. Then create a new instance of the server.
Once you have a client running and change code, the client environment might not know a class you are using. Please add this class by using the #beLoaded method (see existing senders to understand its usage). You might need to manually install it in a running environment (you have to find the corresponding server environment and use #addClass: to add it). Or reload the page in your browser. In some cases this is not enough, because of the order in which classes are installed. In such case you have to close the tab/page and open a new browser tab/page.
The remote code execution capabilities of CodeParadise can be used to create WebApplications, Node.js applications, remote worker instances, mobile applications, etc.
To create WebApplications an MVP (Model View Presenter) pattern is implemented for ease of development. It is based on WebComponents and more specifically it uses the HTML templates technology. The idea is to create a full set of components/widgets to create full featured web applications. All under the control of a Smalltalk application.
Applications can also be 'sealed' allowing them to be run without the need of a Pharo server image. This allows you to create mobile apps, or stand alone Node.js server applications or Node.js CLI tools. This feature is incompatible with the MVP-based applications, since they require communicating with Models and Presenters which run on the Pharo server image.
The means of installing (Compiled) code in the tiny Smalltalk image (aka ClientEnvironment) is by sending the relevant bytecode. The current implementation assumes that both the Pharo server image (aka ServerEnvironment) and the ClientEnvironment share the same bytecode set. Since the ClientEnvironment is running on SqueakJS VM, only bytecode sets supported by SqueakJS VM are usable. Currently Pharo 10 up to 13 (and including) are supported. Active development is on P12. Support for P8 and P9 is no longer provided, because of the non-standard process of creating the tiny Smalltalk image which runs in the browser. From P10 onwards this is standardized using TinyBootstrap. IF you still need support for P8 or P9, please contact me directly or create an issue.
There is no explicit list of supported browsers at the moment. Please use a recent browser version. If you have trouble using (the pre-Chrome based) Microsoft Edge, please consider switching to Chrome, Firefox or one of the derivatives.