Skip to content

Compose

James edited this page Jun 24, 2017 · 2 revisions

🎼 compose

use features as needed

Definitions

const DefaultExt = [Observe, Shorthands, Transform, DotProp]
const Target = class {}

type Exts = Class[] | undefined

// any composable have a .compose method to re-compose them
// default they extend an empty base class
interface Composable extends Class {
	compose: Composer
}

function compose(target?: Class = Target, extensions?: Exts = DefaultExt): Composable

📘 examples

Default

const {compose} = require('chain-able')

// uses default params
class Eh extends compose() {}

Array

const {compose} = require('chain-able')
const {Observe} = compose

class Canada {}
const Composed = compose(Canada, [Observe])

class Eh extends Composed {}

Custom

const {compose} = require('chain-able')
const {Observe} = compose

class Canada {}
const Composed = compose(Canada, [Observe])

class Eh extends Composed {}

Decorators

@compose()
class Eh {}

How?

export classes that dynamically extend a base class, similar to how decorators work, but much faster.

❗ they can be used with decorator syntax as well

module.exports = SuperClass => class Eh extends SuperClass {}
Clone this wiki locally