Browse Source

code review

Falko Schindler 2 năm trước cách đây
mục cha
commit
dfbb756443

+ 1 - 1
nicegui/element.py

@@ -94,7 +94,7 @@ class Element(Visibility):
             'slots': self._collect_slot_dict(),
             'events': [listener.to_dict() for listener in self._event_listeners.values()],
             'libraries': self.libraries,
-            'components': self.components
+            'components': self.components,
         }
 
     @staticmethod

+ 2 - 3
nicegui/elements/chart.py

@@ -108,9 +108,8 @@ class Chart(Element):
         self._props['options'] = options
         self._props['extras'] = extras
         self.use_component('chart')
-        self.use_library('highcharts')
-        self.use_library('highcharts-more')
-        self.use_library('highcharts-3d')
+        for dependency in dependencies:
+            self.use_library(Path(dependency).stem)
         for extra in extras:
             self.use_library(extra)
 

+ 2 - 3
nicegui/elements/chat_message.py

@@ -1,6 +1,5 @@
-from pathlib import Path
-from typing import Optional
 import html
+from pathlib import Path
 from typing import List, Optional, Union
 
 from ..dependencies import register_vue_component
@@ -33,6 +32,7 @@ class ChatMessage(Element):
         :param text_html: render text as HTML (default: False)
         """
         super().__init__('chat_message')
+        self.use_component('chat_message')
 
         if isinstance(text, str):
             text = [text]
@@ -51,4 +51,3 @@ class ChatMessage(Element):
         if avatar is not None:
             self._props['avatar'] = avatar
         self._props['sent'] = sent
-        self.use_component('chat_message')

+ 1 - 1
nicegui/elements/colors.py

@@ -22,6 +22,7 @@ class Colors(Element):
         Sets the main colors (primary, secondary, accent, ...) used by `Quasar <https://quasar.dev/>`_.
         """
         super().__init__('colors')
+        self.use_component('colors')
         self._props['primary'] = primary
         self._props['secondary'] = secondary
         self._props['accent'] = accent
@@ -30,5 +31,4 @@ class Colors(Element):
         self._props['negative'] = negative
         self._props['info'] = info
         self._props['warning'] = warning
-        self.use_component('colors')
         self.update()

+ 1 - 1
nicegui/elements/joystick.py

@@ -28,6 +28,7 @@ class Joystick(Element):
         :param options: arguments like `color` which should be passed to the `underlying nipple.js library <https://github.com/yoannmoinet/nipplejs#options>`_
         """
         super().__init__('joystick')
+        self.use_library('nipplejs')
         self.on('start',
                 lambda _: handle_event(on_start, JoystickEventArguments(sender=self,
                                                                         client=self.client,
@@ -45,4 +46,3 @@ class Joystick(Element):
                                                                       client=self.client,
                                                                       action='end')))
         self._props['options'] = options
-        self.use_library('nipplejs')

+ 1 - 1
nicegui/elements/plotly.py

@@ -28,9 +28,9 @@ class Plotly(Element):
                        a `dict` object with keys `data`, `layout`, `config` (optional).
         """
         super().__init__('plotly')
+        self.use_library('plotly')
 
         self.figure = figure
-        self.use_library('plotly')
         self.update()
 
     def update_figure(self, figure: Union[Dict, go.Figure]):

+ 1 - 1
nicegui/elements/upload.py

@@ -37,11 +37,11 @@ class Upload(DisableableElement):
         :param auto_upload: automatically upload files when they are selected (default: `False`)
         """
         super().__init__(tag='upload')
+        self.use_component('upload')
         self._props['multiple'] = multiple
         self._props['label'] = label
         self._props['auto-upload'] = auto_upload
         self._props['url'] = f'/_nicegui/client/{self.client.id}/upload/{self.id}'
-        self.use_component('upload')
 
         if max_file_size is not None:
             self._props['max-file-size'] = max_file_size

+ 1 - 1
nicegui/functions/refreshable.py

@@ -30,8 +30,8 @@ class refreshable:
     def __call__(self, *args, **kwargs) -> None:
         self.prune()
         with Element('refreshable') as container:
-            self.containers.append((container, args, kwargs))
             container.use_component('refreshable')
+            self.containers.append((container, args, kwargs))
             return self.func(*args, **kwargs) if self.instance is None else self.func(self.instance, *args, **kwargs)
 
     def refresh(self) -> None:

+ 0 - 7
nicegui/outbox.py

@@ -33,13 +33,6 @@ async def loop() -> None:
         try:
             for client_id, elements in update_queue.items():
                 elements = {element_id: element._to_dict() for element_id, element in elements.items()}
-                loading = {
-                    'c': []     # vue components
-                }
-                for element_id, element in elements.items():
-                    for component in element['components']:
-                        loading['c'].append(component)
-                # coros.append(globals.sio.emit('loading', loading, room=client_id))
                 coros.append(globals.sio.emit('update', elements, room=client_id))
             update_queue.clear()
             for client_id, message_type, data in message_queue: