@mangoweb/scripts-base
Advanced tools
Comparing version 0.0.15 to 0.0.16
{ | ||
"name": "@mangoweb/scripts-base", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Simple component model for small to medium sites. Usable from JS & TS.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -13,3 +13,2 @@ # `@mangoweb/scripts-base` | ||
## Usage | ||
@@ -20,2 +19,3 @@ | ||
In your `index.ts` file (or equivalent), use: | ||
```typescript | ||
@@ -26,10 +26,7 @@ import { initializeComponents } from '@mangoweb/scripts-base' | ||
initializeComponents( | ||
[ | ||
MyComponent | ||
], | ||
'initComponents' | ||
) | ||
initializeComponents([MyComponent], 'initComponents') | ||
``` | ||
In your template: | ||
```html | ||
@@ -40,5 +37,6 @@ <script> | ||
place: '#myDiv', // A selector or an element, e.g. `document.body` | ||
data: { // Any data, as required by the component | ||
foo: 123 | ||
} | ||
data: { | ||
// Any data, as required by the component | ||
foo: 123, | ||
}, | ||
}) | ||
@@ -51,4 +49,6 @@ </script> | ||
You must: | ||
- Inherit from `Component` | ||
- Define `static componentName: string` | ||
```typescript | ||
@@ -95,10 +95,13 @@ import { Component, DelegateEvent, EventListeners } from '@mangoweb/scripts-base' | ||
#### Life-cycle methods | ||
The following happens to your component during initialization (in that order): | ||
1) The `constructor` is called (if it exists) as your component is instantialized. | ||
2) Event listeners are attached | ||
3) The `init` method is called (if it exists) | ||
1. The `constructor` is called (if it exists) as your component is instantialized. | ||
2. Event listeners are attached | ||
3. The `init` method is called (if it exists) | ||
You typically don't need to implement a `constructor` but it can be useful to avoid TS2564. | ||
#### Failed initialization | ||
If for whatever reason you decide that the component is unable to run, just throw a `ComponentInitializationError` from either the `constructor` or the `init` method. | ||
@@ -108,2 +111,3 @@ You don't need to worry about any impact on production environment ‒ the error is always caught and its message only displayed when `DEBUG` is `true`. | ||
Valid reasons for yielding and error include: | ||
- Invalid `data` supplied | ||
@@ -121,2 +125,3 @@ - A crucial element in the DOM is not found | ||
To achieve something similar for `el`'s children, you can use `getChild` or `getChildren`: | ||
```typescript | ||
@@ -127,3 +132,5 @@ const link: HTMLAnchorElement = this.getChild('.myLink', HTMLAnchorElement) | ||
#### Property defaults | ||
To get a property value with a default, you can use `getProp`. For example: | ||
```typescript | ||
@@ -138,13 +145,16 @@ const isEnabled = this.getProp('isEnabled', true) | ||
```typescript | ||
import { HidingHeader } from `@mangoweb/hiding-header` | ||
import { InView } from `@mangoweb/in-view` | ||
import { Shapes } from `@mangoweb/shapes` | ||
import { ShapesFallback } from `@mangoweb/shapes-fallback` | ||
import { HidingHeader } from '@mangoweb/hiding-header' | ||
import { InView } from '@mangoweb/in-view' | ||
import { Parallax } from '@mangoweb/parallax' | ||
import { Shapes } from '@mangoweb/shapes' | ||
import { ShapesFallback } from '@mangoweb/shapes-fallback' | ||
``` | ||
There are currently these: | ||
- Emitter | ||
- [HidingHeader](https://www.npmjs.com/package/@mangoweb/hiding-header) | ||
- [InView](https://www.npmjs.com/package/@mangoweb/in-view) | ||
- [Parallax](https://www.npmjs.com/package/@mangoweb/parallax) | ||
- [Shapes](https://www.npmjs.com/package/@mangoweb/shapes) | ||
- [ShapesFallback](https://www.npmjs.com/package/@mangoweb/shapes-fallback) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52168
151