Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

horizon-core

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

horizon-core

Frontend web framework `Horizon`

  • 0.1.0-alpha25
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
324
decreased by-39.66%
Maintainers
0
Weekly downloads
 
Created
Source

Frontend framework Horizon

This is an early build of the project, created for introductory purposes. If you want to participate in the development of the project, you can go to the project in the github

Create first app (Browser render)

Before creating an application, you need to prepare an html file

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Horizon app</title>
    </head>
    <body>
        <div id="app"></div>
        <script type="module" src="./index.js"></script>
    </body>
</html>

File index.js:

import { defineApp, render } from "horizon-core";
import { comp } from "horizon-core/component";

const app = defineApp()

const mainComponent = comp((_, { text, div }) => {
    div({}, () => {
        text('Hello world!')
    })
})

mainComponent.composable.dom = document.body.querySelector('#app') 
    ?? document.body

render(app, mainComponent)

Create first app (Render to string)

import { defineApp, render, toDomString } from "horizon-core";
import { comp } from "horizon-core/component";

const app = defineApp()

const mainComponent = comp((_, { text, div }) => {
    div({}, () => {
        text('Test message')
    })
})

await render(app, mainComponent)

console.log(toDomString(mainComponent.composable))
/* <div hash="$0div"><span hash="$0div0txt">Test message</span></div> */

Signal (aka Reactivity)

Simply example with counter

import { defineApp, render } from "horizon-core";
import { comp } from "horizon-core/component";
import { useSignal } from "horizon-core/state";

const app = defineApp()

const mainComponent = comp((_, { text, $ }) => {
    const counter = useSignal(
        0, { asRaw: value => `Counter: ${value}` }
    )

    $('button', {
        '@click': () => counter.value++
    }, () => {
        text(counter)
    })
})

mainComponent.composable.dom = document.body.querySelector('#app') 
    ?? document.body

render(app, mainComponent)

Using Vite (npm)

Creating vite app with vanilla-ts template

npm create vite@latest horizon-app -- --template vanilla-ts

Install horizon-core

# Installing vite dependencies
npm i
# Installing horizon-core
npm i horizon-core

And edit src/main.ts file

import { defineApp, render } from "horizon-core";
import { comp } from "horizon-core/component";
import { useSignal } from "horizon-core/state";

const app = defineApp()

const mainComponent = comp((_, { text, $ }) => {
    const counter = useSignal(
        0, { asRaw: value => `Counter: ${value}` }
    )

    $('button', {
        '@click': () => counter.value++
    }, () => {
        text(counter)
    })
})

mainComponent.composable.dom = document.body.querySelector('#app') 
    ?? document.body

render(app, mainComponent)

Launch npm run dev

FAQs

Package last updated on 25 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc