Code Monkey home page Code Monkey logo

better-blockly's Introduction

better-blockly

A fully typesafe builder utility for defining Blockly blocks and implementaions in the same place with a focus on DX and type saftey.

Usage

// src/blocks/std.ts

import { createBlockBuilder } from "better-blockly";

// you can also just roll your own base generator 
import pythonGenerator from "blockly/python"; 

const block = createBlockBuilder({
  generator: pythonGenerator,
  customTypes: ["event"],
});

block("something_did_happen")
  .hue(40)
  .outputs("event")
  .content((view) =>
    view
      .text("Something")
      .dropdown("THING", ["Awesome", "Epic"])
      .text("just happened"),
  )
  .impl((block) => `Events.${block.fields.THING}Thing`);

block("wait_for_event")
  .hue(120)
  .extern()
  .slot("target", {
    allow: "event",
    content: (view) => view.text("Wait"),
  })
  .impl((block) => `thread.wait_for_event(${block.resolve("target")})`);

then, in your application make sure to just import 'src/blocks/std.ts'; to load the blocks and voila!

This bit of blockly resolves to "thread.wait_for_event(Events.AwesomeThing)"

better-blockly's People

Contributors

erwijet avatar

Watchers

 avatar

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.