Jelajahi Sumber

stub for listRenderer

Adam Shaw 6 tahun lalu
induk
melakukan
157d8d2bc8
1 mengubah file dengan 36 tambahan dan 1 penghapusan
  1. 36 1
      packages/core/src/view-framework.ts

+ 36 - 1
packages/core/src/view-framework.ts

@@ -519,7 +519,42 @@ export interface ListRendererItem<ComponentType> {
 
 
 
 
 export function listRenderer(): (location: DomLocation, inputs: ListRendererItem<any>[], contextOverride?: any) => Component<any>[] {
 export function listRenderer(): (location: DomLocation, inputs: ListRendererItem<any>[], contextOverride?: any) => Component<any>[] {
-  return null as any
+  let theRenderer
+  let currentComponentClass
+  let currentComponent
+
+  // STUB. works for one element
+  return function(location: DomLocation, inputs: ListRendererItem<any>[], contextOverride?: any): Component<any>[] {
+    let input = inputs[0]
+
+    if (!location || !location.parentEl) {
+      if (theRenderer) {
+        theRenderer.call(this, false)
+        theRenderer = null
+        currentComponentClass = null
+        currentComponent = null
+      }
+
+    } else {
+      if (input.componentClass !== currentComponentClass) {
+        if (theRenderer) {
+          theRenderer.call(this, false)
+          theRenderer = null
+          currentComponentClass = null
+          currentComponent = null
+        }
+      }
+
+      if (!theRenderer) {
+        currentComponentClass = input.componentClass
+        theRenderer = renderer(currentComponentClass)
+      }
+
+      currentComponent = theRenderer.call(this, { ...location, ...input.props }, contextOverride)
+    }
+
+    return currentComponent ? [ currentComponent ] : []
+  }
 }
 }