Giter VIP home page Giter VIP logo

cascade's Introduction

cascade

I swear this is the last DOM library I make (for now)

Create simple, reusable and reactive UI components using render functions and add more complex functionality through method chaining. These methods can be mounted anywhere in the DOM, static applications, with added reactivity only where needed.

// Define reusable component with props
const CounterComponent = El.button().setup(({ self, props }) => {
  const data = ref(props.startingCount as number)

  self.text(() => `Clicked ${data.value} times`)
  self.click(() => {
    if (props.canIncrement.value)
      data.value++
  })
})

///////////////

// Use component somewhere
const App = El.div().setup(({ self }) => {
  const canIncrement = ref(true)

  // This is the same as adding the children inside the El.div(...children).
  // But being able to define this AFTER defining the component logic is much more ergonomic
  self.nest([
    El.h1('Counter'),
    CounterComponent.props({
      // Static prop
      startingCount: 5,
      // Dynamic prop (reactive)
      canIncrement,
    }),
    El.button('Toggle').click(() => canIncrement.value = !canIncrement.value),
  ])
})

App.mount('#app')

TODO

This project started during Christmas, without much thinking through. So far it's been fun and smooth sailing. If this syntax is viable is something future me needs to worry about.

  • [] Props

    • Add passing static data into components
    • [] Correctly type props (using the builder TS pattern)
  • [] else() / elseif() (just complete if() implementation)

  • show()

  • model()

    • input
      • checkbox
      • radio
      • other
    • select
    • details
  • attr()

  • style()

  • Split elements into void and normal components

  • [] destroying and re-mounting components Maybe wrapping every nested method into a function, which saves the whole function and re-runs it on re-mount could work?

  • [] Add template()

    • contains selector for the template defined in the DOM

cascade's People

Contributors

dolanske 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.