2.39.0 • Published 3 years ago

@ecl/ec-auto-init v2.39.0

Weekly downloads
67
License
EUPL-1.1
Repository
github
Last release
3 years ago

ECL Auto init

In order to automatically initialize a component, add data-ecl-auto-init="[component class]" to the root element of the component.

For example, if you want to auto initialize a Message:

<div
  role="alert"
  class="ecl-message ecl-message--info"
  data-ecl-message="true"
  data-ecl-auto-init="Message"
>
  ... Message component ...
</div>

Then, in the footer of the document (or whenever the document is ready), call:

ECL.autoInit();

ECL.autoInit() returns an object containing:

  • list of initialized components
  • update method
  • destroy method
<div
  role="alert"
  class="ecl-message ecl-message--info"
  data-ecl-message="true"
  data-ecl-auto-init="Message"
  data-ecl-auto-initialized="true"
>
  ... Message component ...
</div>

Once ECL.autoInit() is called, you can access the component instance via an ECLMessage property on that element.

document.querySelector('[data-ecl-message]').ECLMessage.handleClickOnClose();

Migration

Please note that the first iteration of ECL.autoInit() was returning only a list of initialized components and you had to call destroy() method of each component individually.

 class MyComponent extends React.Component {
   constructor(props) {
     super(props);
-    this.components = null;
+    this.autoinit = null;
   }

   componentDidMount() {
     if (!window.ECL) return;
-    this.components = window.ECL.autoInit();
+    this.autoinit = window.ECL.autoInit();
   }

   componentDidUpdate() {
     if (!window.ECL) return;
-
-    if (this.components) {
-      this.components.forEach(c => c.destroy());
-    }
-
-    this.components = window.ECL.autoInit();
+    this.autoinit.update();
   }

   componentWillUnmount() {
     if (!window.ECL) return;
-
-    if (this.components) {
-      this.components.forEach(c => c.destroy());
-    }
+    this.autoinit.destroy();
   }

   render() {}
2.39.0

3 years ago

2.38.0

3 years ago

2.37.0

3 years ago

2.36.0

3 years ago

2.35.0

4 years ago

2.34.0

4 years ago

2.33.1

4 years ago

2.33.0

4 years ago

2.32.0

4 years ago

2.31.0

4 years ago

2.30.0

4 years ago

2.29.0

4 years ago

2.28.0

4 years ago

2.28.3

4 years ago

2.27.0

4 years ago

2.26.0

4 years ago

2.25.0

4 years ago

2.24.0

4 years ago

2.23.0

4 years ago

2.22.1

4 years ago

2.22.0

4 years ago

2.21.0

4 years ago

2.20.0

4 years ago

2.19.0

4 years ago

2.18.0

4 years ago

2.17.3

5 years ago

2.17.2

5 years ago

2.17.0

5 years ago

2.16.0

5 years ago

2.15.0

5 years ago

2.14.0

5 years ago

2.13.0

5 years ago

2.12.0

5 years ago

2.11.0

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago