Use Less. Do More.
A research project, from which I learned a lot. Especially how one shouldn't write code and web frameworks in particular :)
In near future, it will be split into several loosely coupled, clean and maintainable NPM modules, for everyone's convenience. Stay tuned.
> npm install useless
Browser builds
- useless.client.js — everything, except devtools
- useless.devtools.js — logging / stacktraces / assertions / Panic.js
Upcoming features
- Splitting of distinct framework parts to separate projects (finally, useful ones).
Recent updates / changelog
-
You can override config with command line args, e.g.
node example webpack.offline=false
, usingserver/config.js
trait. -
You can now handle interactive terminal input with
server/stdin.js
trait. -
ololog logging facility is now separate project (redesigned from a scratch)
-
meta-fields facility now available as a separate NPM module.
-
webpack server trait now supports
compress
option for crunching scripts with Google Closure Compiler. -
Webpack Hot Module Replacement now works (run the example app and try change
example/index.css
). It was previously broken due towebpack-dev-server
incompatilibity with Webpack 2. This is solved by introducingwebpack-hot-fix.js
. -
You can now use ES6 getter syntax for defining properties in components/traits:
get something () { ... }
-
Working on webpack and babel integration for building front-end code (see the webpack server trait and the example app). Will feature continuous builds, hot module replacement, CSS imports and shared code extraction — all configurable from server's config.
-
More NPM modules to come: StackTracey and get-source.
-
ANSI color management now available as separate NPM module: ansicolor.
-
asTable
function now available as a separate NPM module: as-table. -
String.ify
function now available as a separate NPM module: string.ify. -
A wiki entry explaining the Stream concept. Thanks to @kroitor for the translation/adaptation from Russian!
-
Build system now utilizes webpack for squashing
require
imports. All external dependencies (e.g. underscore) now embedded inuseless.client.js
— no need to link them separately. -
Component methods
init / beforeInit / afterInit
now support Promise interface for asynchronous initialization. Old callback-passing style is gone. -
A wiki entry explaining the new __ namespace (brought by Promise+). It contains a pack of highly abstract data-processing algorithms that can handle any type of data (arrays, objects, scalars) and any kind of operator function (either sync or async).
-
An early alpha of the new HTTP server framework built around the recent
Androgene
subsystem. See a brief example here. It allows to write and debug complex asynchronous chains in no time, with unprecedented level of the error reporting legibility. -
A working prototype of Androgene subsystem, delivering the "supervised Promises" concept for asynchronous/nonlinear logging and stack traces. It is also a core mechanism behind the upcoming unit test system (will replace the old
Testosterone
thing).
Running example app
node example
If everything's ok, example app will be running at http://localhost:1333. Currently there's not much example code, but it's on the way.
You may want to look into these projects (built upon Useless.js):
Server app framework
UselessApp =
Example report generated from a Promise chain:
Following are $traits defined at useless/server
:
api.js
URL routingargs.js
command line arguments parsingconfig.js
handlesthis.config
management viaconfig.json
/ command line argumentsexceptions.js
a humane exception printer (replaces Node's default)http.js
powerful HTTP server abstractionipc.js
for app logic splitting between supervisor and supervised processes (RPC for app methods)pidfile.js
generates PID file upon startup / removes it on exitREPL.js
REPL-style debugger (experimental)source.js
remote access to app's own sourcesstdin.js
handling interactive terminal inputsupervisor.js
auto-restart on source code changetemplating.js
Underscore's templates + cachingtests.js
startup smoke tests for app traitsthumbnailer.js
inline thumbnailer for imagesuploads.js
image uploads basicsuptime.js
uptime trackingwebpack.js
full-featured WebPack integrationwebsocket.js
WebSocket basics
Macro processor for prototype definitions
Vec2 = /* Inheritance (relies on native JavaScript prototype semantics) */BetterVec2 =
Component model
- Binds own methods to this automatically
- Manages bindable $trigger / $barrier / $observableProperty members
- Tracks bound components / auto-unbinds upon deinitialization
- Holds parent-child relationship / handles automatic deinitialization
- Enables $traits to chain into method calls by overlapping method definitions
- Enforces configuration contracts ($requires, $defaults)
Multicast model for method calls with simple functional I/O
_.trigger
,_.triggerOnce
/ one-to-many broadcast_.barrier
/ synchronization primitive_.observable
/ state change notifications
Raw API (same for every mentioned primitive):
var mouseMoved = _ /* Binding */ // bind // bind anothermouseMoved // bind with 'once' semantics (auto-unbinds itself upon calling) /* Calling */ // call /* Unbinding */mouseMove // unbinds specific listenermouseMove // unbinds everything_ // unbinds callback from everything it's bound to
Using $component:
Compo = // simply call to perform multicast
compo = compo compo compo compovalue = 10 // simply assign a value to notify listenerscompovalue = 10 // won't trigger, as not changed
Bindable methods for ad-hoc code injection
Raw API:
___
Using $component + 'once' semantics:
Button = button = buttonlayoutbuttonbutton // won't print anything
Math utility for front-end works
Working with ranges:
_ // linear interpolation between min and max _ // clips if out of range /* Projects from one range to another (super useful in widgets implementation) */ _
Vector math (Vec2, Transform, BBox, Bezier, intersections):
var offsetVec = thisanchornormalperp
var where = thisbodyBBox
domElement
Error handling
- Cross-platform uncaught exception handling (works around incomplete 'onerror' impl. in Safari).
- Uncaught exceptions pass through network API calls
- Client displays server's exceptions as if it was single environment
- Complete API for it's internals
- Strips third party calls (clean mode)
- Fetches source code (local/remote)
- Nice output
- Console mode (replaces default Node.js exception printer)
- GUI mode (a pop-up dialog with expandable source lines)
Test framework
- Tests before code
- Tests as documentantion
- Rich library of assertions
- Asynchronous / nested assertions
- Intercepts global log, displaying it in running assertion context
- Custom assertions
- Humane error reporting
- Browser-side support (see demo: youtube.com/watch?v=IWLE8omFnQw)
And more..
- jQuery+ — a pack of handy jQuery plugins
- Node+ — a custom lightweight alternative to jQuery
- DOMReference — traits for writing DOM-rendered components
- DSL for writing regexps in JS + named subexpressions