0.1.0 • Published 6 years ago

intr v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

Intr

Is a runtime library for partial support of interfaces in JavaScript.

Basic Usage

// Define some classes with empty methods (interfaces)
class Greeter {
    say() {}
}

class Serializable {
    serialize() {}
}


// Implements all methods from Greeter and Serializable
class Test extends intr([Greeter, Serializable]) {
  say() {
      alert('YO!')
  }

  serialize() {
      return 'serialized
  }
}

If the class you are writing needs to extends a base class, it can be passed as the second argument to intr like so

class Person {
    constructor({firstName, lastName}) {
        this.firstName = firstName
        this.lastName = lastName
    }
}
class Greeter() {
    greet() {}
}

class Waitress extends intr([Greeter], Person) {
    greet() {
        const {firstName, lastName} = this
        alert(`Welcome! My name is ${firstName} ${lastName}`)
    }
}

If any of the methods were missing in the implementation, an Exception gets thrown.

Disabling in Production

If intr detects that it is running in production, no checks will be performed.

Specifially the this code class B extends intr(A) {} becomes, effectively, class B {}.