core/head
The head represents the library and its accessibles. In the browser this manifests as the
first object to loadout: Polypoint.
The head contains a range of hoisting functions to late-load installables.
Quick Guide
Install a class:
Polypoint.head.install(PointListPen)
Deferred prop (called once to generate):
class PointConstraints {}
Polypoint.head.deferredProp('Point',
function constraint() {
return new PointConstraints(this)
}
);
Install Functions:
Polypoint.installFunctions('Point', {
track(other, settings) {
return constraints.distance(other, this, settings)
}
, leash(other, settings) {
return constraints.within(other, this, settings)
}
});
Install more complex Mixins (defineProperties):
Polypoint.head.mixin('Point', {
isNaN: {
value(any=false) {
//...
return false
}
, writable: true
}
, distanceTo: {
value(other) {
return distance(this, other)
}
}
, distance2D: {
value(other) {
return distance2D(this, other)
}
}
})
Usage
- Add this file
- Load assets with
Polypoint.head.install()...
Once loaded, assets are available through the same object Polypoint.MyClass
Example
We can load standardclasses:
class A {
foo() {
return 'foo'
}
}
class B extends A {
bar() {
return 'bar'
}
}
class C extends B {
baz() {
return 'baz'
}
}
Polypoint.head.install(A)
Polypoint.head.install(B)
Polypoint.head.install(C)
Once loaded, we can access them within the object:
Polypoint.A
// class A ...
And target the loaded classes for live property mixin:
Polypoint.head.mixin('C', {
one: {
get() {
return 'one'
}
}
})
c = new C;
c.one == 'one'
This can occur late, and decent through dependant children:
// Property on _c_ does not exist yet.
c.two == undefined
// Load a property into "B"
Polypoint.head.mixin('B', {
two: {
get() {
return 'two'
}
}
})
// New B as the new property.
b = new B;
b.two == 'two'
// Existing "C" instances gain the new property.
c.two == 'two'
This works for many mixins:
// Another late mixin, targeting the root class
Polypoint.head.mixin('A', {
three: {
get() {
return 'three'
}
}
})
// All (a,b,c) instances gain the new property
(new A).three == 'three'
b.three == 'three'
c.three == 'three'
Meta Data
| filepath_exists | True |
| path | core/head |
| filepath | core/head.js |
| clean_files | () |