Orthogonal is a JavaScript library providing:
- dependency injection,
- a store,
- a cache, &
- a bunch of utility methods
The philosophy when designing Orthogonal has been "worse but better".
See, e.g., klr-monster for a real-world example.
function do_expensive_stuff($cache) {
return $cache.get('cache-key', () => {
// do the stuff
});
}
orthogonal.call(do_expensive_stuff); // injects $cache
// onReady is a utility method, which calls a dependency-injected version
// of the function you pass it either directly, if the DOM is loaded, or
// on window.load.
orthogonal.onReady(($css, $store) => { // inject $css and $store
const menuStore = $store // create a new store
.state({
header: {
isDetached: false,
height: 0
},
isMobile: false
})
.actions({
updateHeader: (state, {isDetached, height}) => ({...state, header: { isDetached, height }}),
updateIsMobile: (state, isMobile) => ({ ...state, isMobile }),
});
// $css contains helpers for working with $css, see `./orthogonal.extensions.js`
const [headerClass, detachedClass] = $css.classNames('header', 'detached'); // => ['header', 'header--detached']
const header = document.querySelector(`.${headerClass}`);
// => $css.getVar() parses and returns css variables
const mobileBreakpoint = +$css.getVar('--breakpoint-mobile').replace('px', '');
// subscribe to changes of the value at the path `header.isDetached` in the store
menuStore.select('header.isDetached')
.subscribe((detached) => header.classList.toggle(detachedClass, detached));
});
Check the API-documentation for more information.