Scope: A Web Programming Language To-Be

2 min read Original article ↗

What’s Scope look like?

Scope is released Open Source under the MIT license, and is available on NPM and GitHub.

The base language is pretty well done, but the libraries are hardly started. There’s no way (7/29/2018) to create a server or client yet, but a proposed way resembles this (which I posted earlier as a reply on reddit):

let server = httpServer((client: []) {
client.socket.on("buttonClick", {
client.find("#serverEmits").text("Message from Outer-space");
});
client.response.send(site);
});
let tellServer = (e: []) {
server.socket.emit("buttonClick");
};
let button = <button onClick=tellServer>
"Click me";
</button>;
let site =
<html>
<head>
<title>Example Site</title>;
</head>;
<body>
<div id="serverEmits"></div>;
button;
</body>;
</html>;

This would be a simple server that sends the XML-type value “site” to the client. When the button is clicked, the server receives a message for the “buttonClick” tag, and then sends a socket message back to the client that modifies an element with the ID “serverEmits”, causing a message to appear above the button that says “Message from Outer-space”.

The above code should make sense for traditional web developers. A proposed way to abstract I/O:

let server = httpServer((client: []) {
public message = "";
public repeatText = (data: "") {
message = data;
};
client.response.send(site);
});
let txt = <input type="text" bindIn=server.repeatText />;let site =
<html>
<head>
<title>Example Site</title>;
</head>;
<body>
<div bindOut=server.message"></div>;
txt;
</body>;
</html>;

Now it’s a bit different. When text input is changed, the server updates the `message` property. Because the div is bound to that same message property, whenever `message` is changed the client updates it’s inner-html with the value of server.message.