Hello my fellow developer, considering that you are reading this post, the title got you intrigued, didn't it? Well, stick with me until the end an...
For further actions, you may consider blocking this person and/or reporting abuse
It depends on your favorite paradigm. ReactJS code tends to be functional. Let me tell you the way how a React component get rendered on browser.
An application needs a currentUser, so i create a
withAuth
higher order component.A component needs to authorize that currentUser to display/allow/disallow action on that component, so i create a
withPermissions
hoc.A page needs a layout, so i create a
withLayout
hoc.A component might get rendered differently based on current route, so i create a
withRouter
hoc.In the end, your page is rendered as
I must say, i love this style of application design and implementation also.
In Vue, i couldn't, because the way to code Vue is to use a Vue component, not function.
Or am i missing something in Vue ?
Actually there are functional components in Vue. The document says
Hi, your question was already answered by Ozan. As you can see, Vue does support JSX as well. And I agree with you that everything is in personal preference when you have great frameworks to choose between.
For the specific example you've given, my first instinct would be to check out Vue mixins. The react team has a different philosophy about mixins and prefer compositions as you've shown. Could read Dan Abramov's "Mixins considered harmful" article for their perspective. On the other hand, The Vuetify library is an interesting Material implementation that relies heavily on Vue's mixins.
Maybe Stencil can help you. He generates web components that can be integrated with other frameworks (Angular, React, Vue) or can be used without a framework (stenciljs.com/docs/javascript).
And use it like this:
Wow! I can write similar code with Vue + TypeScript (feat. Vue Property Decorator).
Nice, but I personally like the Stencil syntax.
Did you know the web platform has its own built-in component model? You can use shadow DOM to encapsulate your css - no more compound selectors, verbose naming conventions, preprocessors, etc. You can define your own html elements with custom elements and add your special behaviours, and you can efficiently render with template elements.
Check out my series on web components to learn more.
Lets Build Web Components! Part 1: The Standards
Benny Powers
Hi, yes, I'm aware of the web components and the shadow DOM, but I didn't get super deep into them. Very useful features, but it feels like that on every new project we need to recreate the framework.
The web components standards are very low-level. You're really not meant to use the vanilla APIs exclusively for large projects. On some projects, like you said, the best choice will be to write your own library to handle things like data binding, data flow, state container etc. But in most cases, the smart move will be to use an off-the shelf base class like LitElement for your components, with a state container like redux, or for example lit-apollo for graphql projects.
You can also use web components inside your existing framework code, since they are just html elements. I've used web components to solve problems in existing Vue apps, for example.
Starting a new angular project is very easy. Install the cli and node, type in
ng new projectName
in the terminal and then you can start writing code!Hi, yes, but I just wanted to do a simple Hello World example comparison. I think installing CLI and Node is a bit overkill in that scenario.