by laichzeit0 · 11y ago · 0 comments
So the problem for me was not React being bad or Angular better but at the end of the day it has to do with: As a non-fulltime webdev I need a _complete_ widget/component library available for when I want to build my apps. With React I felt like I was constantly either having to look for components that kind-of/sort-of worked for me but had some short falls or I had to build them from scratch. Then there's the look and feel so you're either looking for components that are Bootstrap ready or Material Design-ish, etc. Even then, you take Angular Material: it's not there yet. Go to the website. That side-nav menu they have going is really nice. I wanted to use that in my app. Is that an MD component? Nope. It's a hacked together mess of custom things. Talk about "eating your own dog food".
Is this common place in the web world right now? Regardless of choosing React/Angular/whatever. I mean I'm used to QT. There's a widget for just about anything. You just wire up your events and you have an app. It seems like the web world is slowly just going to end up reinventing Delphi at the end of the day when I look at things like Polymer (why has it taken so long?)
All these frameworks are great but can we please just work on having feature-rich components/widgets now. And maybe keep them maintained for the next 5 years or so?
So a lot of the work that traditionally went into widget/VCLs/etc. is immediately not necessary and probably even unwanted. You basically have to reivent large parts of the wheel anyway. The rest is often largely component-independent, mostly event handling and data binding. So a very generic component often wouldn't help you that much, which is why a lot of the MVC libraries and frameworks available often seem to "skip" that part.
One noticeable exception is ExtJS, which seems the single remaining major toolkit aiming at desktop-like applications. There you've got your standard FormPanels, GridEditors and AbstractSelectionModels. There the tables turn, and HTML/CSS is often just used as the totally abstracted away presentation layer, and you just arrange widgets in JavaScript. That means a considerable payload, and more problems if you actually need to have something more "web-like" (boy, the horror of XTemplate).
For enterprise/intranet apps this matters less, of course. Which is why Ext is still rather common there and why they can afford to actually demand money for their library, despite all the competition.
But again, you probably wouldn't build gmail/instagram/facebook with Ext.
The problem with React is that the core team has explicitly stated that they are not worried about compatibility with Web Components, so if you stick with that framework over the long term you may find yourself shut out of that bright future. The Angular team re-wrote their framework mainly because they wanted to be compatible with the upcoming Web Components spec.
So, yes, it's a mess, but it's about to get a lot better. Hop over to https://www.polymer-project.org/1.0/ to get a glimpse of things to come.
What's great about Web Components is that they don't need custom developer tools. The DOM tree _is_ your component tree, the browser naturally highlights custom elements, just like built-in elements. Editing the DOM and CSS just works. Placing an element into a temp variable and setting properties just works.
No. This is the web. We must reinvent everything every 5 minutes.
You might want to check more enterprisy frameworks like extjs.
One of the reasons I've seriously been considering React for even a lot of back-end stuff is that it's really easy to create an isolated component that combines markup, styling and behavior. Once done, I can simply require() the component on either the back- or front-end, or both, and reuse the component in other projects.
Granted, for styling there's still no solution that I consider optimal, but the advantages might be worth the 'impurity' of it all. And solutions are being worked on.
And granted, there are other initiatives like Web Components that are hopeful.
But already now React is a great option if you want to create 'independent' and re-usable components. I think it's just a matter of time before a proper, popular component-ecosystem arrives, and what with React Native, there might even be some degree of 'unification' across platforms.
That's assuming we won't abandon React en masse and switch to another even cooler solution in a few years, though :-/.
[1] https://docs.reduxframework.com/core/getting-started/ [2] https://github.com/acdlite/redux-react-router [3] http://material-ui.com/ [4] https://github.com/erikras/react-redux-universal-hot-example...
React isn't that. That's fine - it's not supposed to be.
Hell Angular isn't that... but as it's a framework (React really isn't it's a View library) it has more of that. Angular + Bootstrap probably does most of what you would want...
... but it's an extremely narrow need. Not a general case.
I was under the impression that at the end of the day you're creating either React components and/or Angular directives when you're building a web application. And the particular framework takes care of how the view changes when the model changes, it provides you with some abstractions like Resources (to talk to REST APIs) and Routers (for navigation). Even when you look at ExtJS I don't see why they couldn't provide ReactExtJS or AngularExtJS by just wrapping their widgets so that you're either creating them with "props" or by specifying the initial "scope" if you're doing it Angular directives, for example.
Creating standardized widgets which can be "wrapped" to expose a React (prop/state) or Angular (isolated scope directive) style interface, and then "skinned" (Bootstrap or Material Design or whatever) I would have thought would be the logical thing to do. As another poster commented, perhaps this is what people are calling "Components"? However, I'm pretty sure it could be done right now with what we currently have.
If you say it's an extremely narrow need, I understand because typically I end up facing problems no one else seem to have :)
Toolkits of the kind you're looking for (ExtJS/Dojo etc) just haven't really taken off. ExtJS suffers from having an all or nothing approach to its usage, and last I checked its approach left much to be desired. Dojo is a bit more flexible in that sense but both libraries are big and complicated as they have to do a lot of work to achieve the behaviour they require of the browser.
Browsers simply aren't designed (still!) to provide the grid-like layouts required by apps. It's generally best to avoid the complexity required to do this unless you have no choice.
Flexbox promises to make grid layouts much easier. I have to admit, the last time I tried to work with it I found it quite difficult to get to work for me.
Web components promise to raise the number of available HTML elements by creating your own. The are indended to help you move from code like `$('.datepicker').datePicker()` to HTML like `<datepicker />`.
Fundamentally, there is not going to be a standard way of doing things on the web because there is no such thing as a standard website. When you visit a website today, you could be visiting an API, an RSS news feed, a database interface), a drawing package, a computer game, etc.
Such diversity of applications requires a diversity of tools and approaches, and that is what we are seeing a proliferation of today as we explore and discover the most successful ways of providing digital content.
I like your idea of writing generic code and then expose it to Angular/React/Ember.
Including something like Backbone/JQuery would probably be harder, since it uses direct DOM manipulation. But those other frameworks have livecycle-hooks that get called when a component is rendered and have to provide the framework with virtual-dom/handlebars/etc.-templates that get injected at the right position.
Since A/R/E don't have their own CSS (contrary to ExtJS) the styling code could be generic too (which it already is in most web-apps, with the help of Bootstrap).
We "can", and maybe there are already quit a few. However, the thing about UI is that it's more than the sum of its parts; experience is holistic, and a UI should be conceived as a whole, not as something assembled by common components.
This is fundamentally a difference between disciplines. As a developer, you'll think that reusable and isolated/modular widgets are the way to go; a UI designer, on the other hand (and not forgetting consistency), will/should(!) adapt the UI to its users and contexts.
Keep in mind though, the environment QT runs in is very different to the web, so most of us poor web devs are at the mercy of browser vendors, and as such we're often limited by the lowest common denominator.
This thing will never change, whether with React or Angular.
Web dev, due to custom design of pages, is not like using native (Cocoa, Windows Forms etc) widgets where one-size-fits-all. It's more like native apps with custom skins and widgets.
The first and most basic is that the expectation on the web is that every project will have a unique look and feel. This greatly limits the adoption of frameworks based on desktop widget library concepts (dojo, ext, sencha, cappuccino, sproutcore). The times I've used these frameworks, I spend as much time fighting the look and feel as I would building an interface from scratch. This isn't a problem if you're look and feel insensitive and desktop style widget libraries do get picked up for internal corporate apps.
The second problem is size. The need to download everything, desire for reduced page load times, and lack of dead code elimination has historically made web devs more sensitive to the size of their libraries. This was a problem for libraries like YUI2, which had excellent components that simply had an option for anything somebody at yahoo wanted but adding a new widget would frequently add hundreds of K to the download. This is a reduced concern with the increased capabilities of mobile and I believe that the combination of HTTP2, having a standard module system, increased tooling (e.g. webpack), universal/isomorphic JS, and ServiceWorker provide the means to more or less eliminate this as a core problem.
The third problem is CSS. The language provides no tools for abstraction when the target markup (your widget) is fixed. Happily, this problem is solved via sass. You can separate style concerns into mixins (or placeholders) and compose them into either widget or instance specific rules and avoid the cascade.
The fourth problem is component composition. In order to get more code reuse, you need to be able to build up bigger widgets from small pieces and then make a lot of useful small pieces. Stateful components don't compose particularly well and I've spent a lot of time on this (in yui3, knockout, and angular) before I found React's virtual dom approach two years ago. With the vdom, it's possible to view components as functions projecting state onto a virutal DOM. Composition can then be solved by creating higher order components and using normal functional programming composition and code reuse. With care put in to how larger components are designed, it's possible (I've done it) to swap out sub components to customize behavior on a per-instance basis. I consider the core problem solved but I haven't seen the equivalent of an underscore for react components yet.
The fifth problem is widget interaction. I define widgets as components that are an isolated concern (and generally maintain internal state): Autocomplete instead of FooList. Since the components are generally stateful and produce events, you have to have a protocol for having them interact with each other and the rest of the app. As an example, a FOO widget is a React component has PropTypes that get compiled into a Falcor query and all its event handlers call a function `dispatch` with an object shaped like X. Everybody comes up with this in their app but without a consensus on what the approach is, everybody's widget libraries are parochial. This is an active area of development and Web Components is Google's take on the problem. Facebook is also very interested in this with Flux/GraphQL.
Once all the problems are solved (I believe we're relatively close) then we should see widget libraries come into their own. I'm estimating about 3 years before someone starts really winning the widget library battle and we get a "standard" set of widgets you're looking for. I believe that something from the React or Ember communities are the likely source and Polymer has an outside chance (I don't see how component composition works in Polymer).
Because standards, you can compose Polymer elements with native elements or custom elements built with or without a helper library like Polymer.
What part is confusing?
Thank you for posting this. I've been wondering if this was possible. Can you share any insights that might help someone that wants to do this?
// In your components...
let DefaultListItem = (content) => <li className="foo">{content}</li>
let DefaultList = (items, Li=DefaultListItem) => <ul>{items.map(Li)}</ul>
let SortableItem = (content) => <li className="handle" on-drag={(e) => dispatch('dragStart', hash(content))>{content}</li>
let SortableList = (items, Li=SortableItem) => <DefaultList {...this.props} />
let EditableList = (items, List=DefaultList, Li=SortableItem) => {
<div><List {...this.props} /><button>Edit</button></div>
}
let SearchResultHighlighter = (text) => <span className="imagine-this-highlighted">{text}</span>
// -- In use...
let source = ['foo', 'bar', 'baz']
render(<SortableList items={ source.map(SearchResultHighlighter) } />)
let ImageItem = (url) => <li><img src={url} /></li>
render(<EditableList items={ source.map(x => x + '.jpg') } Li={ImageItem} />)
There's a lot of design space to play around with. For a widely reusable library, I want something like Clojure's protocols or Rust's traits so I can indicate to people what the component needs/provides without them looking at the source.