-
Notifications
You must be signed in to change notification settings - Fork 0
Erector Module Definition
Matthew Dzaman edited this page Oct 18, 2019
·
2 revisions
To export erector
as a template tag with properties that provide access to all helper methods, as well as export each helper method individually.
import * as module from './lib/erector';
// module.erector is a template tag
// module[helper_name] is a helper method (if, cmp, and, or, etc.)
// module.erector[helper_name] is a helper method
Also keep types functional and minimize boilerplate.
Use function
and namespace
merging.
- define
Erector
class - create
IErector
interface as function and properties- e.g.
{ (strings, exps): Statement; raw: Raw... }
-
deal breaker:
IErector
interface must repeat function signatures fromErector
class - this could also be done without an interface, which would make
erector
an instance of a union type, which would be nice to avoid
- e.g.
- assign
erector: IErector
usingObject.assign(fn, properties)
- set properties to
Erector.*
- set properties to
- export assignment of
erector.*
to const*
in the main module
- functions defined in
erector
namespace as constants -
erector
function defined as a template tag function - re-exported with assignment of
erector.*
to const*
in main module - pros
- only one signature/definition per function and one extra assignment
-
erector.*
functions havethis
- cons
-
erector.if
cannot be defined *- cannot defined
if
on erector in namespace - cannot export
_if as if
from namespace - * - can modify erector namespace in main module
- cannot defined
-