@dnncommunity/dnn-elements 0.17.0-beta.1 → 0.17.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -557,16 +557,17 @@ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) =>
557
557
  * @param vnodes a list of virtual DOM nodes to remove
558
558
  * @param startIdx the index at which to start removing nodes (inclusive)
559
559
  * @param endIdx the index at which to stop removing nodes (inclusive)
560
- * @param vnode a VNode
561
- * @param elm an element
562
560
  */
563
- const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
564
- for (; startIdx <= endIdx; ++startIdx) {
565
- if ((vnode = vnodes[startIdx])) {
566
- elm = vnode.$elm$;
567
- callNodeRefs(vnode);
568
- // remove the vnode's element from the dom
569
- elm.remove();
561
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
562
+ for (let index = startIdx; index <= endIdx; ++index) {
563
+ const vnode = vnodes[index];
564
+ if (vnode) {
565
+ const elm = vnode.$elm$;
566
+ nullifyVNodeRefs(vnode);
567
+ if (elm) {
568
+ // remove the vnode's element from the dom
569
+ elm.remove();
570
+ }
570
571
  }
571
572
  }
572
573
  };
@@ -825,10 +826,17 @@ const patch = (oldVNode, newVNode) => {
825
826
  elm.data = text;
826
827
  }
827
828
  };
828
- const callNodeRefs = (vNode) => {
829
+ /**
830
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by
831
+ * calling them with `null`. This signals that the DOM element corresponding to
832
+ * the VDom node has been removed from the DOM.
833
+ *
834
+ * @param vNode a virtual DOM node
835
+ */
836
+ const nullifyVNodeRefs = (vNode) => {
829
837
  {
830
838
  vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
831
- vNode.$children$ && vNode.$children$.map(callNodeRefs);
839
+ vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
832
840
  }
833
841
  };
834
842
  /**
@@ -883,10 +891,32 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
883
891
  const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
884
892
  return writeTask(dispatch) ;
885
893
  };
894
+ /**
895
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
896
+ * component lifecycle methods like `componentWillLoad` as well as
897
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
898
+ *
899
+ * @param hostRef a reference to a host DOM node
900
+ * @param isInitialLoad whether we're on the initial load or not
901
+ * @returns an empty Promise which is used to enqueue a series of operations for
902
+ * the component
903
+ */
886
904
  const dispatchHooks = (hostRef, isInitialLoad) => {
887
905
  const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
888
906
  const instance = hostRef.$lazyInstance$ ;
889
- let promise;
907
+ // We're going to use this variable together with `enqueue` to implement a
908
+ // little promise-based queue. We start out with it `undefined`. When we add
909
+ // the first function to the queue we'll set this variable to be that
910
+ // function's return value. When we attempt to add subsequent values to the
911
+ // queue we'll check that value and, if it was a `Promise`, we'll then chain
912
+ // the new function off of that `Promise` using `.then()`. This will give our
913
+ // queue two nice properties:
914
+ //
915
+ // 1. If all functions added to the queue are synchronous they'll be called
916
+ // synchronously right away.
917
+ // 2. If all functions added to the queue are asynchronous they'll all be
918
+ // called in order after `dispatchHooks` exits.
919
+ let maybePromise;
890
920
  if (isInitialLoad) {
891
921
  {
892
922
  hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
@@ -896,14 +926,35 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
896
926
  }
897
927
  }
898
928
  {
899
- promise = safeCall(instance, 'componentWillLoad');
929
+ // If `componentWillLoad` returns a `Promise` then we want to wait on
930
+ // whatever's going on in that `Promise` before we launch into
931
+ // rendering the component, doing other lifecycle stuff, etc. So
932
+ // in that case we assign the returned promise to the variable we
933
+ // declared above to hold a possible 'queueing' Promise
934
+ maybePromise = safeCall(instance, 'componentWillLoad');
900
935
  }
901
936
  }
902
937
  endSchedule();
903
- return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
938
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
904
939
  };
940
+ /**
941
+ * This function uses a Promise to implement a simple first-in, first-out queue
942
+ * of functions to be called.
943
+ *
944
+ * The queue is ordered on the basis of the first argument. If it's
945
+ * `undefined`, then nothing is on the queue yet, so the provided function can
946
+ * be called synchronously (although note that this function may return a
947
+ * `Promise`). The idea is that then the return value of that enqueueing
948
+ * operation is kept around, so that if it was a `Promise` then subsequent
949
+ * functions can be enqueued by calling this function again with that `Promise`
950
+ * as the first argument.
951
+ *
952
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
953
+ * @param fn a function to enqueue
954
+ * @returns either a `Promise` or the return value of the provided function
955
+ */
956
+ const enqueue = (maybePromise, fn) => maybePromise instanceof Promise ? maybePromise.then(fn) : fn();
905
957
  const updateComponent = async (hostRef, instance, isInitialLoad) => {
906
- // updateComponent
907
958
  const elm = hostRef.$hostElement$;
908
959
  const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
909
960
  const rc = elm['s-rc'];
@@ -1029,9 +1080,6 @@ const safeCall = (instance, method, arg) => {
1029
1080
  }
1030
1081
  return undefined;
1031
1082
  };
1032
- const then = (promise, thenFn) => {
1033
- return promise && promise.then ? promise.then(thenFn) : thenFn();
1034
- };
1035
1083
  const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1036
1084
  ;
1037
1085
  const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
@@ -1195,9 +1243,9 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1195
1243
  const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1196
1244
  // initializeComponent
1197
1245
  if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1246
+ // Let the runtime know that the component has been initialized
1247
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1198
1248
  {
1199
- // we haven't initialized this element yet
1200
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1201
1249
  // lazy loaded components
1202
1250
  // request the component's implementation to be
1203
1251
  // wired up with the host element
@@ -1584,4 +1632,4 @@ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1584
1632
 
1585
1633
  export { Host as H, consoleError as a, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
1586
1634
 
1587
- //# sourceMappingURL=index-7d9efdb8.js.map
1635
+ //# sourceMappingURL=index-a7be395c.js.map