StrictDuck is a retroactive inheritance system for javascript. It aims to solve the problem of runtime object opacity and identity to allow for higher level abstractions, such as the "self aware" component composition in strictduck-control-inverted.
The default
export is the StrictDuck
class, which all StrictDucks inherit from.
StrictDuck
does the following:
* assigns the first argument to the new instance
* leverages duckface to ensure the new instance implements the interfaces specified in the rest of the arguments
* assigns the object the key { [Symbol('strictduck.id')] : Symbol(strictDuckClassName) }
, giving us a more dependable way to identify object inheritance
Another key export is extend
, which is used for tersely specifying StrictDucks, such as the Main
export:
export const Main = extend({ name: 'Main', methods: ['main'] })
exports id
, equals
, and is
are used for identifying strictducks (every StrictDuck class has id
as a key) and comparing them.
import {Main, equals, is} from 'strictduck'
let instance = new Main(mainObj)
equals(instance.prototype, Main) == true
is({instance, Class: Main}) == true
The implement
export is used for specifying the implementation of a strictduck class, such as strictduck-domain-driven-fullstack/Domain#implementation.
The implementable
export is a small function for creating overridable default options. An example usage looks like strictduck-domain-driven-fullstack/client.
I consider both implement
and implementable
clunky and possibly unnecessary, and hope to remove them eventually.
StrictDuck and strictduck-control-inverted are the cornerstone of bufflehead and it's various components. The overarching goal of the strictduck project is to bring "runtime self awareness" to javascript, and then build higher level abstractions utilizing that.
StrictDuck is untested for projects that don't use polypacker as the build tool. In fact, it's only tested by it's usage elsewhere.