def entry(self): createElement = Object.get('window', 'React', 'createElement') if self.entry_function[0] is None: if self.component_object is not None: return self.component_object if self.component is None: return Object.fromString( 'This is the default RPython render text, override render method to get started' ) if self.component.startswith( 'RPYJSON:') and self.component.endswith(':RPYJSON'): path = JSON.parse_rpy_json(self.component) component = Object(path).keep() if component.type in ['null', 'undefined']: Error( 'Trying to get component in path %s but the type is %s' % (path, component.type)) self.component = component.toRef() #elif self.component.startswith('RPYJSOBJECT:') and self.component.endswith(':RPYJSOBJECT'): #component = Object(self.component, safe_json=True) #if component.type in ['null', 'undefined']: # print 'Trying to get component in path %s but the type is %s' % (self.component, component.type) #self.component = component.toRef() if self.children is None or not self.children: return createElement.call(self.component, JSON.fromDict(self.native_props)) return createElement.call( self.component, JSON.fromDict(self.native_props), JSON.fromList([ children.entry().toRef() for children in self.children if children is not None ]) if len(self.children) > 1 else self.children[0].entry().toRef() if self.children[0] is not None else None) #fromChildren(self.children, cache=False)) #assert self.entry_function[0] is not None #self.rpython_count['count'] += 1 #id = str(self.rpython_count['count']) id = Object.get('window', 'Math', 'random').call().toString() self.rpython_caches[id] = self self.native_props['rpython_cache_id'] = id if self.pure_component: self.props = Object.fromDict(self.native_props) return self.render().entry() if self.children is None or not self.children: return createElement.call( JSON.fromFunction(self.entry_function[0]), JSON.fromDict(self.native_props)) return createElement.call( JSON.fromFunction(self.entry_function[0]), JSON.fromDict(self.native_props), JSON.fromList([ children.entry().toRef() for children in self.children if children is not None ]) if len(self.children) > 1 else self.children[0].entry().toRef() if self.children[0] is not None else None) #fromChildren(self.children))
def fromChildren(children, cache=True): refs = [] for object in children: if object not in object_cache: object_cache[object] = None if object is None else object.entry( ).toRef() refs += [object_cache[object]] return JSON.fromList(refs)