Comments (11)
- use injections <my-tag template-provider="{myTemplateProvider}" ...>
- before the element is created, declare the injection Slim.inject('myTemplateProvider', () => templateProviderInstance)
- on the class itself, declare a template getter.... class MyClass { get template() { return this.myTemplateProvider.getTemplate() } }
during the creation routine the injection will take place, during the rendering phase it will take the template string from the provider
for that tag, don't use the template decorator
from slim.js.
Please let me know if that works for you and we can close this thread
from slim.js.
the Example component's prototype will have a template getter that returns null.
Try in your main.ts doing this:
template(templateProvider.templates['sws-example'])
class SomeNewElementClass extends ExampleComponent {}
let eC = new SomeNewElementClass()
can you put your code in webpackbin or similar?
from slim.js.
I did put together a sandbox in webpackbin
https://www.webpackbin.com/bins/-KpPuTpl9q-E_E6KSmBr
And we here at the office wanted to ask you, if there is a specific reason why you emit "Illegal constructor TypeError" and do not allow injections? Or is there a possible fork that we can provide to the issue?
With very kind regards and thanks for you help
tilman
from slim.js.
for some reason i cannot edit or view any of the files in your bin
from slim.js.
basically, custom elements should not have arguments in their constructors, as they are created from the HTML. slim provides an injection mechanism (currently not yet documented) that is invoked between the "onBeforeCreated" and "onCreated". example:
<my-element some-property="{injectionName}"></my-element>
and in your source code best used before the HTML is created
let SomeSingleton = new MySingleton();
Slim.inject('injectionName', (element) => {
//element is optional
return SomeSingleton;
})
...
@tag('my-element')
class extends Slim {
onCreated() {
console.log(this.someProperty); // Injection!
}
}
if The injection is declared before (or any other element using the injection) then you will have access to the injection result at the designated property
from slim.js.
you just have to click on Copy Bin in the left sidebar than you can edit you own derivative.
from slim.js.
I'm not sure what you are trying to achieve. If you want to use arbitrary templates, wrap them in template tag and not use existing declared custom element tag
...
do you wish to inject your template during runtime from template provider?
from slim.js.
yes, that was the idea. We are building an app that is unfortunately strongly backend rendering based and I have to avoid duplicate dom at runtime at a minimum. I found a way around within our workflow.
from slim.js.
hey Avichay, due to the many issues I had trying to implement with your library I had to drop it for the current project. But I understand how difficult it is to concentrate on certain features of a library.
from slim.js.
:( what was the problematic feature that made you drop it?
from slim.js.
Related Issues (20)
- package.json.module is pointing to an unexisting file HOT 1
- Storybook components HOT 2
- Typing for attributeChangedCallback lacks parameters HOT 1
- WEBP Support HOT 3
- "Uncaught TypeError" when using slim-js with @babel/preset-env HOT 4
- s:if Conditional rendering not working HOT 9
- [SUGGESTION] Provide a way to take outter css in the shadowDOM HOT 2
- Non-minified package distribution HOT 1
- if directive inside foreach directive HOT 3
- Idea for cleaner templates HOT 1
- Unresponsive counter component HOT 2
- Documentation Site - "Oops, this page does not exists" HOT 1
- How does the property directive work? HOT 11
- Query in template css class name does not work in object usage only in object creation HOT 1
- Issue with Webpack exports
- How to setup vscode with `/*html*/` and typings HOT 2
- Links broken on slimjs.org HOT 1
- What is the point of this library? HOT 1
- Is this repo still active? HOT 2
- How to use the CDN?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slim.js.