webcomponent_base module

Create simple statefull lit-html webcomponent backed with Sqlalchemy.

Example

>>> # ... Init flask app and webcomponent extension ...
>>> class User(db.Moel):
>>>     username = db.Column(db.String(80), nullable=False)
>>> # ... Flask app and extensions setup ...
in html template: <user-item index=1></user-item>
class webcomponent_base.FlaskWelApp(__name__, cors_allowed_origins=[])

Bases: flask.app.Flask

runApp(**kwargs)
class webcomponent_base.IndexModel

Bases: flask_sqlalchemy.model.Model

Webcomponent base class with an Integer index as primary key

classmethod configure_blueprint(base_url=None, component_name=None, template=None, external_url=None)

Configure element

Configure the element with convenient default values.

Parameters
  • base_url (String) – API endpoint for the component. Default to /classname

  • component_name (String) – the registered html tag name. Default to classname (lowercase)

  • template (String) – Template name for the webcomponents. Default to classname.html

  • external_url (String) – External url for the API. Same Resource Scheme required. Default to internal base_url

Returns blueprint for flask

delete(index)

Delete webcomponent instance with index index. Emit delete signal

dump()

Return all index as {‘items’: [list of item]}

emit_delete()

emit Webcomponent.delete(index) SocketIO signal

emit_update()

emit Webcomponent.update(index) SocketIO signal

get(index)

Return webcomponent instance value as json. HTTP GET.

get_all()

Return all index as {‘items’: [list of indexes]}

post()

Save webcomponent instance value from json. HTTP POST. Emit update signal

webcomponent()

Send the webcomponent.js dependancies

webcomponent_base.get_socketio()
webcomponent_base.init_webcomponent(app, sqlAlchemydb=None, socket_io=None)

Init webcomponent with external dependancies

sqlAlchemydb store object state, and socket_io allows efficient communication between browser and flask’s webcomponent REST API

Parameters
  • app (Flask) – Init webcomponent with App.config values

  • sqlAlchemydb (SQLAlchemy) – Your database storing webcomponent state has to be instanciated with SQLAlchemy(app, model_class=IndexModel).

  • socket_io (SocketIO) – The streaming object instance.