Ubercharge everything with reactivity
npm i uberscript
import {
uber, signal, mux, monitor, mapProps, isUberObject, isUberSignal
} from 'uberscript'
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)
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)
})
Apply a mixin
Wrapper for ubered.get
and ubered.set
Wrapper for ubered.fn
Create a signal:
const count = signal(0)
count.connect(val => console.log(val)) // logs 0
count += 1 // logs 1
Connect a handler method to a signal
Disconnect a handler method to a signal
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
Auto connect current method to all signals been called inside
Creates a mixin that maps props automatically
Checks if an object is ubered:
const uberObject = uber(() => () => {})
const myObject = {}
const uberedObject = uberObject()
isUberObject(myObject) // false
isUberObject(uberedObject) // true
Checks if an method is an uber signal:
const myFn = () => {}
const mySignal = signal(null)
isUberSignal(myFn) // false
isUberSignal(mySignal) // true
MIT