예제 #1
0
파일: constructor.py 프로젝트: soIu/pyrex
 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))
예제 #2
0
def unmount_state(component):
    states = Object.get('Module', 'pyrex_state_cache')
    if states.type == 'undefined':
        Object.get('Module')['pyrex_state_cache'] = JSON.fromDict({})
        states = Object.get('Module', 'pyrex_state_cache')
    key = component.props['rpython_cache_id'].toString()
    Object('delete Module.pyrex_state_cache[%s]' %
           key)  #TODO Implement __del__ in Object
예제 #3
0
def initial_state(component, initial=None):
    states = Object.get('Module', 'pyrex_state_cache')
    if states.type == 'undefined':
        Object.get('Module')['pyrex_state_cache'] = JSON.fromDict({})
        states = Object.get('Module', 'pyrex_state_cache')
    key = component.props['rpython_cache_id'].toString()
    state = states[key]
    if state.type == 'undefined':
        states[key] = Object('{}' if initial is None else initial,
                             safe_json=True).toRef()
        state = states[key]
    return state
예제 #4
0
파일: constructor.py 프로젝트: soIu/pyrex
 def setState(self):
     #if self.state_function is None: return
     self.state_function.call(JSON.fromDict({}))