Skip to content
Bunshi
GitHub

moleculeInterface

moleculeInterface<T>(): MoleculeInterface< T >

Create a new molecule interface.

Molecule interfaces don’t define an implementation, only a reference that other molecules can depend on for an implementation. Before an interface can be used, an implementation needs to be provided in the bindings to an MoleculeInjector. If no bindings for an interface exist, then an error will be thrown the firs time it is used.

Interfaces can be bound to molecules, scoped molecules, or molecules that simply wrap scopes.

Interfaces are useful for decoupling your application and for library authors when the implementation that your molecule relies on is unknown or variable. For example if your writing a molecule that relies on router state, but there are many possible routers and no standard routers.

Avoid interfaces when your library or application has a good default implementation. For example, if your molecule relies on making HTTP requests, then it’s better to have a molecule that provides http access via fetch than an empty interface. Since molecules can also be replaced in bindings, it is more convenient for consumers of your molecules to have a default implementation provided.

Type parameters

ParameterDescription
Tthe typescript interface that this interface provides

Returns

MoleculeInterface< T >

Source

molecule.ts:145