-
Notifications
You must be signed in to change notification settings - Fork 219
Conversation
Holy shit, this is amazing! I can even nest them. |
If I read the source correctly, this doesn't support the shadow DOM. Is that on purpose? |
@danieldiekmeier no, sorry, I've forgot to add it. I'll try to update this PR in the next days. |
If possible would be cool if there was a way to get access to the inner need this On Nov 5, 2016 1:39 PM, "Karol Fabjańczuk" [email protected] wrote:
|
(reverted from commit 11fa3c1)
That's a huge step towards vue 2.0 support, i tried it with some rewriting to vue 2 syntax and it works, but seems it doesn't support
map-markers would be placed in place of docs: https://vuejs.org/v2/guide/components.html#Single-Slot |
@dariuszsikorski I would suggest creating wrapping vue-element with template with google-maps and map-marker, which will be simple vue components. |
@karol-f What you suggest is to move |
@dariuszsikorski I think your requirements are valid. Unfortunately in at least two weeks time I probably won't be able to try to implement it. I'll remember about it and try to implement it along with migration to v1 spec of WebComponents and HMR reload. Thanks. |
@karol-f I'm trying to use your Vue.element, but not getting what I need. My first question is from other global javascript code, how to retrieve and use the reference of a vue component inside your vue element? If I have , then ....$refs.myvueelement seems to return dom node directly which behaves differently than regular Vue.component. Also, I specified shadow:true in options, but saw no effect. I did see a new attr ve-ready like <myvue-element ... ve-ready> when I inspect. Appreciate your help. |
@johnjunpeng Hi, I'll try to answer: 1). Reference to vue component is held in 2). About As stated in https://www.webcomponents.org/polyfills#shadow-dom-polyfill it's hard to polyfill that and using alternatives is preferred 3).
Regards! |
@karol-f Thanks a lot for the quick response. I tried your way using Thanks again and best regards! John |
@johnjunpeng Hi Regarding triggering method on child component. Wouldn't it be easier to trigger to trigger it just by changing attribute or prop? Check example - https://jsfiddle.net/zL4zxz7e/. As you can see, method is triggered by using In your approach it should be also doable. About Regarding Shadow Dom - Probably you didn't put it into third parameter of Regards |
@karol-f Thanks again for the details. Yes, it was my bad, I didn't pass shadow: true as the 3rd parameter, but 2nd one as you said. I should have read your documentation more carefully. So shadow-root is created and working properly in Chrome. Your simple example on jsfiddle is very helpful and works in both chrome and firefox. But somehow I could not make my code work in firefox (upon dom inspection, I saw empty element Usage for Vue.element() is the same as Vue.component() - you pass in exactly the same options as if you are defining a Vue component. A few things to note: Nested Vue custom elements are not supported - it is recommended to use Vue's own component system inside a custom element; The custom element interface is intended for inter-op with other libraries (e.g. Polymer). You don't need to manually instantiate a root level Vue instance. Custom Elements get auto-promoted when document.registerElement is called. You can also freely define the element before or after the markup. Real custom elements must contain a hyphen in its tag name. For example, my-element is valid, but myelement is not. You can expose attributes with Vue's props (0.12) or paramAttributes (0.11) option, but you can only pass in literal values (no dynamic bindings). See the example folder to see it in action. By default the element does not use Shadow DOM. If you want to enable Shadow DOM encapsulation, pass in shadow: true in your component options. |
About your specific use case, when you want trigger callback from child. It would be much easier if you prepare JS Fiddle so I can check it. Thanks. Regards! |
@yyx990803 Can we decide what to do with this PR? I suggest two options:
What should we choose? |
@karol-f Thank you again! I tried your polyfill using Best Regards! |
@johnjunpeng Please check if your app works with IE11 without As you can see in Regards. |
In IE 11, I got the below error Thanks! |
@johnjunpeng As you see in demo it's working even in IE9. Please create JS Fiddle or it will very hard to nail the problem. One thing that comes to my mind is that in IE you have to check $refs in Regards. |
OK, thanks. I'll try but it may take me a while to create a code snippet to demo my case on JS Fiddle. Sorry, I am new to Vue, but what is |
@johnjunpeng Here you are https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram. |
@karol-f Thank you very much! I've found the root cause of my issue in IE 11. The performance of the whole thing is much slower in IE than Chrome and Firefox. (Your js fiddle example was also displayed much slower in IE than Chrome and Firefox) Therefore |
@karol-f I found out mounted callback is executed before
|
@johnjunpeng it should work too:
Regards! |
@karol-f Vue.nextTick() indeed solved this problem on IE. Unfortunately I retested this same code on Firefox and found out it still suffered the same issue: |
@johnjunpeng I would love to help but this PR is not a place to solve your problem. Please create issue on my repo and prepare JS Fiddle showing problem and describing what you want to achieve. Regards! @yyx990803 Please respond to #9 (comment) so we can finally close this PR and decide what to do next. I know that you are busy man so a lot of comments in this thread don't help, sorry about that. |
@karol-f You might have to email/Twitter-message him directly, seems Evan shut off notifications. Maybe wait to Tuesday just in case. |
Thanks @karol-f for your enthusiastic contribution! But I'm quite concerned about many semantic issues and library distribution issues which need more discussion:
Every aspect requires design decision. I'm quite afraid that one decision change could force whole implementation rewrite. |
Thanks for good questions! |
Hey @karol-f , thanks again for the effort. First, the decision: I think we should deprecate the current repo and let you create a separate repo for this. The general idea is that anything under the However, the significant changes you made in this PR makes it essentially a completely new project - and more importantly, your project. I really think it's better for you to take ownership. To be clear, we'd love to collaborate with you to improve the project so that it becomes the de-facto solution for Vue + Custom Element integration, but it doesn't necessarily mean it must be hosted in the Now for the feedback - @HerringtonDarkholme raised a bunch of good questions. Here are some of mine:
|
If anyone is interested, @HerringtonDarkholme
Distibution
I've tested Webpack@1 (7,7 Kb), Webpack@2 (8,1 Kb) and Rollup (7 Kb). Indeed, Rollup filesize was smallest so
Unfortunately it's not that simple. We cannot simply extend native HTML elements (babel/babel#4480). Due to that I use https://github.com/github/babel-plugin-transform-custom-element-classes which uses
It's desirable as
Compatibility with versions < 1 is done with 7 lines of code. Gzip'ped difference is 0.04 Kb. Do you think it's worth it?
Wow, that's a nice idea. I will need some help with that though. I'll start an 'issue' with it (karol-f#2) and we can implement it. Thanks and regards! |
@yyx990803 TL;DR is the Vue core team looking into embracing the idea of creating native custom elements with Vue? I'm currently conducting a broad research which should result in a recommendation for my organization. Because we're building a platform for software development, the recommendation may result in choosing a technology for a number of applications in at least several years to come. We did a similar choice ~3 years ago when we planned a PoC application for the platform. We chose Angular JS. For some time we were very happy with the framework. We delivered features with speed and quality. But then Angular 2 happened. I'm sure I don't need to tell you that the stakeholders are not happy about where we end up with our initial choice. Even though I can explain the stakeholders what happened to Angular JS and why it happened, it does not make them less worried about the future. All they ask now is how we can minimize the risk of this same thing happening to the technology we choose this time. I can't blame them. Usually when developers look for business stability they look for corporate backing and community strength. This is valid. But to me the most underestimated point here is the spec compliance. For this reason I chose ES6 over CoffeeScript once and last couple of years did prove it a much better choice. As of now, web components are emerging and since they are a part of the spec, I'm strongly leaning towards incorporating them in some way in our technology stack. In the past few days I've been looking at how modern web frameworks intersect with native web components. Obviously I came across This PR was closed and I did see the explanation. But maybe the decision had something to do with Vue 2 being in progress. Or some other plans for web components compliance. I'm sure there are more people like me trying to make safe choices but at the same time work with new exciting technologies. So again, is the Vue core team looking into embracing the idea of creating native custom elements with Vue? Is there a roadmap and a timeline? Thanks for getting all the way down here. |
@ennovum I feel the same. Choosing Web Components (for me Custom Elements and maybe Shadow Dom) is the key for future-proof rewrites. My comment for Gutenberg project seeking for new technical fron-end stack - WordPress/gutenberg#2733 (comment) In short I think that wrapping any framework with Custom Element and communicating using standard non-changable API is future-proof as you can change your underlying FE technology one component at the time. IMHO It's something like microservices for frontend. |
What we will likely do: provide a CLI option that compiles Vue components directly into distributable custom elements (similar to stencil.js). But overall I still see the value of WC being more about interop / distribution rather than the "safety bet" many seem to think of it as. WC alone gives you too little for meaningful app development, even with WC being the underlying composition unit, you will still need a higher-level framework like Polymer, Stencil or Vue to support actual development. At that level you are back to ground zero when making the decisions, WC simply becomes the new baseline. |
@yyx990803 thanks for your reply. To me web components as the new baseline is not nothing. And I expect the spec of web components to grow and give us more and more features in time. So if I knew that a framework's architect is into embracing the standards and building with them in mind, I'd be more eager to put my trust into this framework being the safe choice I need. Is there even a vague date to the CLI option you mentioned? |
Completely rewritten Vue-element plugin, full-featured, with docs and demos.
Docs - https://github.com/karol-f/vue-element/tree/wip/master/vue_2_element
Demos - https://karol-f.github.io/vue-element/ (GithubPages served from 'docs' folder)
Description
Vue-element
is a tiny wrapper around Vue components. It provide seamless way to use it in HTML, plain JavaScript, Vue, React, Angular etc., using power of Custom Elements.Why you might need
Vue-element
?It might be confusing for users to understand difference between Vue components, Custom Elements and it's use cases.
Why you might need
Vue-element
? Simply, for your Vue components user's convinience. All they would need to do is include your JavaScript file and then they can:<my-component><my-component />
) in any time of document lifecycle. You can use your elements in e.g. SPA application just by including HTML tag - no Vue initialization or JavaScript usage is needed. Custom Elements will auto initialize when mounted into document. You can include them in e.g. Vue, Angular or React projects and browser will take care of detecting it and initializationFeatures
tag-name
and Vue componentobject
is needed forVue.element()
usageIt's rewritten using ES6, proper build process, prepared for future tests. Feel free to ask questions.
Regards.