Giter Club home page Giter Club logo

coed's People

Contributors

eeue56 avatar stoivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

stoivo

coed's Issues

Can't get example from readme to work

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.