0.0.1 • Published 1 year ago

uberscript v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

UberScript

Ubercharge everything with reactivity

Usage

Install

npm i uberscript

Import

import {
	uber, signal, mux, monitor, mapProps, isUberObject, isUberSignal
} from 'uberscript'

Play around

const uberConsole = uber(() => () => console)
.set('log', ({$}) => (val) => $.log(val))
.set('warn', ({$}) => (val) => $.warn(val))

const count = signal(0)
const myConsole = uberConsole()

myConsole.log(mux`Count is ${count}`)
myConsole.warn(mux`Doubled count is ${() => count() * 2}`)

count(i => i + 1)

API

uber

Ubercharge anything:

const uberInput = uber((init) => (text) => {
	init((self) => {
		self.value(text)
		if (isUberSignal(text)) self.onInput(text)
	})
	return document.createElement('input')
})
.props('value')
.event('onInput', ({$}) => (trigger) => {
	$.addEventListener('input', () => {
		trigger($.value)
	})
	return () => $.removeEventListener('input', handler)
})

ubered.fn

ubered.get

ubered.set

ubered.event

ubered.mixin

Apply a mixin

ubered.props

Wrapper for ubered.get and ubered.set

ubered.methods

Wrapper for ubered.fn

signal

Create a signal:

const count = signal(0)

count.connect(val => console.log(val)) // logs 0

count += 1 // logs 1

sig.connect

Connect a handler method to a signal

sig.disconnect

Disconnect a handler method to a signal

mux

Create a reactive string:

const count = signal(0)
const countStr = mux`Count is ${count}`

countStr.connect(val => console.log(val)) // logs Count is 0

count += 1 // logs Count is 1

muxed.connect

muxed.disconnect

muxed.pause

muxed.resume

muxed.batch

muxed.flush

muxed.watch

monitor

Auto connect current method to all signals been called inside

mapProps

Creates a mixin that maps props automatically

isUberObject

Checks if an object is ubered:

const uberObject = uber(() => () => {})

const myObject = {}
const uberedObject = uberObject()

isUberObject(myObject) // false
isUberObject(uberedObject) // true

isUberSignal

Checks if an method is an uber signal:

const myFn = () => {}
const mySignal = signal(null)

isUberSignal(myFn) // false
isUberSignal(mySignal) // true

License

MIT

0.0.1

1 year ago

0.0.0

1 year ago