Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
# Import from another module
self._import(mod_name, val.__name__, name)
elif isinstance(val, type) and issubclass(val, bsdf.Extension):
# A bit hacky mechanism to define BSDF extensions that also work in JS.
# todo: can we make this better? See also app/_component2.py (issue #429)
js = 'var %s = {name: "%s"' % (name, val.name)
for mname in ('match', 'encode', 'decode'):
func = getattr(val, mname + '_js')
funccode = py2js(func, indent=1, inline_stdlib=False, docstrings=False)
js += ',\n ' + mname + ':' + funccode.split('=', 1)[1].rstrip(' \n;')
self._collect_dependencies(funccode, _dep_stack)
js += '};\n'
js += 'serializer.add_extension(%s);\n' % name
js = JSString(js)
js.meta = funccode.meta
self._pscript_code[name] = js
self._deps.setdefault('flexx.app._clientcore',
['flexx.app._clientcore']).append('serializer')
elif isinstance(val, pscript_types) and hasattr(val, '__module__'):
# Looks like something we can convert using PScript
mod_name = get_mod_name(val)
if mod_name == self.name:
# Define here
try:
js = py2js(val, inline_stdlib=False, docstrings=False)
except Exception as err:
t = 'JS in "%s" uses %r but cannot transpile it with PScript:\n%s'
raise ValueError(t % (self.filename, name, str(err)))
self._provided_names.add(name)
def _get_js_of_base_classes(cls):
""" Get JS for BaseAppComponent, LocalComponent, and ProxyComponent.
"""
c1 = create_js_component_class(BaseAppComponent, 'BaseAppComponent',
'Component.prototype')
c2 = create_js_component_class(LocalComponent, 'LocalComponent',
'BaseAppComponent.prototype')
c3 = create_js_component_class(ProxyComponent, 'ProxyComponent',
'BaseAppComponent.prototype')
c4 = create_js_component_class(StubComponent, 'StubComponent',
'BaseAppComponent.prototype')
meta = c1.meta
for k in ['vars_unknown', 'vars_global', 'std_functions', 'std_methods']:
for c in (c2, c3, c4):
meta[k].update(c.meta[k])
js = JSString('\n'.join([c1, c2, c3, c4]))
js.meta = meta
return js
def attach_meta(self, s):
s = JSString(s)
s.meta = self.meta
return s
# Add this class
c = create_js_component_class(cls.JS, cls_name, base_class_name)
meta = c.meta
code.append(c)
# code.append(c.replace('var %s =' % cls_name,
# 'var %s = flexx.classes.%s =' % (cls_name, cls_name), 1))
# Add JS version of the base classes - but only once
if cls.__name__ == 'JsComponent':
c = cls._get_js_of_base_classes()
for k in ['vars_unknown', 'vars_global', 'std_functions', 'std_methods']:
meta[k].update(c.meta[k])
code.insert(0, c)
# Return with meta info
js = JSString('\n'.join(code))
js.meta = meta
return js