diff --git a/Makefile b/Makefile index 5b40fe1..4f96137 100644 --- a/Makefile +++ b/Makefile @@ -34,13 +34,14 @@ build: ## Build pypi package python3 -m poetry build generatejs: ## Build javascript + python3 -m pymake rebuildcustompreact python3 -m poetry run transcrypt -da -sf -de -m -n -b -ds -dc mything python3 -c "print('moving generated js to docs/api/js/');import shutil;import os;os.chdir('__target__');files = os.listdir(); match = lambda file: file.endswith('.js'); move = lambda file: (os.path.exists('../docs/api/js/'+file) and os.remove('../docs/api/js/'+file)) or shutil.move(file, '../docs/api/js/'); list(map(move,filter(match, files)))" rebuildcustompreact: ## Download and minify custom preact browserify deps " npm i browserify preact proppy proppy-preact uglify-js - ./node_modules/.bin/browserify docs/api/custom-preact.browserify.js -o docs/api/custom-preact.js - ./node_modules/.bin/uglifyjs docs/api/custom-preact.js -o docs/api/custom-preact.min.js + ./node_modules/.bin/browserify docs/api/js/custom-preact.browserify.js -o docs/api/js/custom-preact.js + ./node_modules/.bin/uglifyjs docs/api/js/custom-preact.js -o docs/api/js/custom-preact.min.js tdd: ## Run tests on file change python3 -m poetry run ptw diff --git a/docs/api/_headers b/docs/api/_headers new file mode 100644 index 0000000..c776a47 --- /dev/null +++ b/docs/api/_headers @@ -0,0 +1,2 @@ +/* + Access-Control-Allow-Origin: * diff --git a/docs/api/js/custom-preact.browserify.js b/docs/api/js/custom-preact.browserify.js index ceb2c70..3f5e89e 100644 --- a/docs/api/js/custom-preact.browserify.js +++ b/docs/api/js/custom-preact.browserify.js @@ -1,10 +1,10 @@ window.CustomHtml = window.CustomHtml || {}; var preact = require('preact'); -for (var i in preact) { window.CustomHtml[i] = preact[i]; } +for (var i in preact) { window.CustomHtml[i] = preact[i] } var proppy = require('proppy'); -for (var i in proppy) { window.CustomHtml[i] = proppy[i]; } +for (var i in proppy) { window.CustomHtml[i] = proppy[i] } var proppyPreact = require('proppy-preact'); -for (var i in proppyPreact) { window.CustomHtml[i] = proppyPreact[i]; } +for (var i in proppyPreact) { window.CustomHtml[i] = proppyPreact[i] } diff --git a/mything/microfrontends/core/__init__.py b/mything/microfrontends/core/__init__.py index 704f363..eeed275 100644 --- a/mything/microfrontends/core/__init__.py +++ b/mything/microfrontends/core/__init__.py @@ -31,12 +31,11 @@ def mount(self, tag: str, attributes: typing.List, instance: IFrontend): class PureCssWebComponent(IComponent): def mount(self, tag: str, attributes: typing.List, instance: IFrontend): - def mounter(html, element, mountPoint, style, instance, attributes): + def mounter(html, element, mountPoint, style, instance, attributes, Provider): attrs = dict() for item in attributes: attrs[item] = element.getAttribute(item) - custom = instance.view(attrs) - provider = html.h(html.ProppyProvider, {}, [custom]) + provider = html.h(Provider, None, [instance.view(attrs)]) html.render(provider, mountPoint) root = element.attachShadow({ 'mode': 'open' }) style.setAttribute('rel','stylesheet') @@ -44,9 +43,10 @@ def mounter(html, element, mountPoint, style, instance, attributes): style.setAttribute('type','text/css') root.appendChild(style) root.appendChild(mountPoint) - - def cb(html, me, create): - mounter(html, me, create("span"), create("link"), instance, attributes) - # __pragma__ ('js', '{}', 'class cls extends HTMLElement{connectedCallback(){cb(window.CustomHtml, this, x => document.createElement(x))}}') + def connect(html, me, create): + mounter(html, me, create("span"), create("link"), instance, attributes, html.ProppyProvider) + + # call customElements.define with class that calls connect + # __pragma__ ('js', '{}', 'class cls extends HTMLElement{connectedCallback(){connect(window.CustomHtml, this, x => document.createElement(x))}}') # __pragma__ ('js', '{}', 'window.customElements.define(tag, cls, attributes);') diff --git a/mything/microfrontends/counter/CounterFrontend.py b/mything/microfrontends/counter/CounterFrontend.py index 1288bb3..f4f20e0 100644 --- a/mything/microfrontends/counter/CounterFrontend.py +++ b/mything/microfrontends/counter/CounterFrontend.py @@ -10,11 +10,13 @@ def config(self): self._html.withProps({'page': 'Home'}), self._html.withState('counter', 'setCounter', 0) ) - - def view(self, props={'page':'Home', 'counter':0, 'setCounter':lambda x: None}): - root = self._html.h('div', {}, [ + + def root(self, props={'page':'Home', 'counter':0, 'setCounter':lambda x: None}): + return self._html.h('div', {}, [ props['page'], props['counter'], self._html.h('button', {'class':'pure-button pure-button-primary','onClick': lambda: props['setCounter'](props['counter']+1)}, '+1') ]) - return self._html.attach(self.config(), root) + + def view(self, props): + return self._html.h(self._html.attach(self.config())(self.root))