eeue56 / coed Goto Github PK
View Code? Open in Web Editor NEWElm-style library for writing modern frontends
License: BSD 3-Clause "New" or "Revised" License
Elm-style library for writing modern frontends
License: BSD 3-Clause "New" or "Revised" License
Could be that I am doing something wrong but it looks like the readme example is some type checker errors.
I changed it to this to make it work
import { HtmlNode, div, on, style_, text } from "@eeue56/coed";
import * as coed from "@eeue56/coed";
type FlipName = { kind: 'FlipName' }
function FlipName(): Msg {
return {
kind: "FlipName",
};
}
type Msg = FlipName;
type Model = { name: string; }
function update(msg: Msg, model: Model): Model {
switch (msg.kind){
case 'FlipName':
if (model.name === 'Noah') {
return { name: 'Ianto' };
} else {
return { name: 'Noah' };
}
}
}
function view(model: Model): HtmlNode<Msg> {
return div(
[ on("click", () => FlipName()) ],
[ style_("color", model.name === "Noah" ? 'green' : 'red') ],
[ text(model.name) ]
);
}
function main() {
const root = document.getElementById("root");
if (root === null) return;
const program = coed.program({
root: root,
initialModel: { name: "Noah" },
view: view,
update: update,
});
}
main();
diff --git a/app/coed/index.ts b/app/coed/index.ts
index 8381f2d..5d04e43 100644
--- a/app/coed/index.ts
+++ b/app/coed/index.ts
@@ -1,7 +1,13 @@
-import { HtmlNode, div, onClick, style_, text } from "@eeue56/coed";
+import { HtmlNode, div, on, style_, text } from "@eeue56/coed";
import * as coed from "@eeue56/coed";
type FlipName = { kind: 'FlipName' }
+function FlipName(): Msg {
+ return {
+ kind: "FlipName",
+ };
+}
+
type Msg = FlipName;
type Model = { name: string; }
@@ -16,21 +22,24 @@ function update(msg: Msg, model: Model): Model {
}
}
-function view<Msg>(model: Model): HtmlNode<Msg> {
+function view(model: Model): HtmlNode<Msg> {
return div(
- [ onClick(() => FlipName()) ],
- [ style_("color", model.name === "Noah" ? 'green' : 'red') ]
+ [ on("click", () => FlipName()) ],
+ [ style_("color", model.name === "Noah" ? 'green' : 'red') ],
[ text(model.name) ]
);
}
function main() {
- const root = document.getElementById('root');
+ const root = document.getElementById("root");
+ if (root === null) return;
const program = coed.program({
- root: root
+ root: root,
initialModel: { name: "Noah" },
view: view,
update: update,
});
}
+
+main();
Maybe I doing it wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.