WebComponent support seems to be super spotty across browsers. But that being said, it's an incredibly exciting extension to HTML so really cool that Google's invested the time to flesh out what a WC-based widget library might look like.
Clearly software should be written more efficiently so that his phone is still capable. The LG G2 is a two year old smartphone. It's pretty unacceptable that something doesn't run well on it, so long as the underlying software (operating system and browsers) are up to date.
Basically, there's a layer of polyfills called the Platform that will disappear as browsers implement key web platform features natively. On top of that is the main Polymer library, which is a small sugaring library that makes using the individual Platform polyfills together a lot easier. On top of that are a couple different sets of both UI and non-UI web components built using Polymer, namely core-elements and paper-elements.
They're only similar in that they're both for building component based DOM UI.
Polymer is tied into the WebComponents standardization effort (also driven by google-related people). Pieces of the DOM are managed by relatively small, contained objects that maintain their own internal state and keep the DOM in sync. It achieves component state synchronization via data binding like Angular or Ember and some sort of KVO mechanism (eventually Object.observe if they're not using that already, I haven't looked at their code in a couple months).
When you write code for React, on the other hand, you basically pretend the DOM is stateless and write your code as if you're writing server side templating code and rendering the entire page from scratch. The framework takes the data structure that the render process builds and efficiently forces the DOM to match what was rendered. At least that's the central concept. There are plenty of caveats.
If anybody has more specific questions, I'm happy to answer them.
Mixing them both together would be nasty (components are central to both APIs, it'd be counterintuitive), but using React as a fallback layer doesn't sounds so bad
Haven't tried it but you can integrate React with pretty much anything. Looking at the Polymer lifecycle methods[1], I'd start by trying a `React.renderComponent` in Polymer's `domReady` callback for an element and then setState/setProps/forceUpdate in the `attributeChanged` callback.
That said, I don't expect it to be common since you'd basically be building a React component with a Polymer shim and getting almost no leverage out of Polymer. I suppose you could write some code to parse out the html template and turn it into React.DOM equivalents but that seems like a lot of effort.
All React integrations I've seen are the result of introducing React into a legacy codebase or they're using React on a component that's rendering a very large DOM subtree and taking advantage of React's O(N_view) instead of O(N_model) scaling and batched updates for perf wins over current KVO techniques.
That's not really doable. I'm building a React based component/widget system for work and assuming all goes well and I can OSS it there's a reasonable chance I'll build out a Material/Paper widget set since I really like this set of design guidelines.
Completely agree that the Polymer Material "look and feel" is really nice and well thought out. The WebComponents ideas it is based on gives me the jibblies though.
You could do the polymer look and feel with the react update model via famo.us (disclaimer: I work for famo.us). Famo.us also plays pretty nicely with Ember.js (tutorials coming soon) and React.js.
As much as I want to like web components, Google's behavior with this new "standard" has been very suspect. The "intent to ship" thread from February this year is something everyone should check out.
Here is Maciej Stachowiak's response to Google's irresponsibility on the intent to ship announcement:
Shoehorning more and much junk into HTML, a markup language with only two types, strings and children, will likely result in bad juju. It may be great for setting things up declaratively, but not for controlling something with state that changes over time. It will serve to reduce what's possible instead of enabling others to explore ideas on the web that are currently only possible in native.
What we need is a low-level retain mode scene graph with a JavaScript API. DOM is a pretty inadequate replacement for a real scene graph. DOM is simply too costly to manipulate and re-arrange and I don't see what WebComponents does to fix that problem.
This might delay the crisis the web feels relative to native, but will just punt the problem a few years down the road at best.
Lastly, some required reading for anyone who wants to educate themselves on the Shadow DOM:
I was kind of confused as to the organization of the repos and how this is all brought together. Is there a document somewhere explaining the relationship (hierarchy) of all the repos and what role each plays in the larger polymer material project?
Specifically, where is the code that does the layout for this? I want to see how they are doing the positioning of elements in space. Is it all CSS classes or do they do positioning with javascript?
On one hand, I worry that Google is monopolizing the future of the web, but on another, I'm glad because they are effective at producing the features that us developers want.
I have mixed feelings about Polymer, currently its high browser requirements make it too radical to use at work (IE, Firefox & Safari be broken yo), but forward enough to get me experimenting with it on my personal projects. At the workplace, I'll continue to stick to React.
I love the look and feel that went into the design of Material here, but with respect to web components, we should be worried that Google is monopolizing the future of the web. See my comment below: https://news.ycombinator.com/item?id=7947119
It bugs me that Polymer is being marketed as "polyfills", since the term polyfill generally tends to connote something that fills in for an already agreed upon w3c standard that will appear in all user agents eventually. Whereas web components and shadow dom is still very much in the proposal/experimentation stage and has a ways to go before reaching standardization. There are still some disagreements to be resolved by all those that contribute code to the major user agents.
Calling polymer a polyfills library is misleading and an abuse of the intent of the term polyfill [0].
Also related: "Apple Removes Shadow DOM from Safari"[1][2]
What a strange strange choice. Instead of moving responsibilities to a imperfect but very flexible turing-complete language (javascript), they are trying to shoehorn everything into a markup language originally designed as an abstraction for documents (html).
I liked a lot of what I saw in the project, but this "ajax as an element" makes me want to facepalm, or at least scratch my head and wonder "why?!?"
Can someone from the polymer team elaborate the reasoning behind this?
I'm sure I want to defend this particular implementation without looking at it more but 'declarative' is quite a nice programming style as long as you can easily override it with 'proper' code when you hit it's limits - see Django's models, forms, admin etc.
Totally agree with declarative code that can be overridden with "proper" code. However in this particular instance, the declarative API in HTML for getting a resource at a particular URI already exists in the form of the "href" property. I don't understand what AJAX here adds at all, since it's not congruous with the semantics of the term AJAX -> "Asynchronous Javascript and XML". There is no javascript there. There's no notion of "asynchronicity" in a declarative interface since async connotes flow control. And the XML (part) used to refer to the original data structure format that was retrieved, whereas most people these days use JSON and even this example uses JSON.
It's not even clear from this example, what is done with the JSON data fetched here. It's not assigned to a variable or returned by a callback. The script below the element in fact uses globals to access the code, since that is basically what `document.querySelector` does. Putting stuff in the DOM is the equivalent of saving all your variables on the window object and then accessing them with `window.myDomElement`, but in a more verbose, indirect and non-performant way.
Furthermore, I noticed in some of the markup elements, the addition of a "url" property. How does "url" differ from "href", especially, when all the examples I saw had URIs pointing to *.html hypertext documents. Is "url" a new property that exists in a standard somewhere? If not, I was under the impression that non-standard HTML properties are supposed to be prefixed.
What are you taking about?
It's still javascript, javascript encapsulated in elements. You can view source code, make your own, and release it is custom elements.
<polymer-ajax
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"alt":"json", "q":"chrome"}'
handleAs="json"
auto
></polymer-ajax>
... is not JavaScript. I see XML where there is one tag with 4 properties. Not a line of JavaScript there.
Furthermore, it involves putting data in the DOM (e.g. the `params` property above), where getters and setters now need to go through the inefficient steps of serializing plain old javascript objects when setting a property and parsing a string as a JSON object when getting a JSON property.
"Best thing happend in web in a long time IMHO."
This is one of those times, when it's worth asking yourself the question "Hmmmm... putting everything in the DOM... What could possibly go wrong?"
The simple fact that the DOM is the only thing that is not accessible to web workers should be a massive red flag. DOM is popular with noobs because it represents global state, which is easy to work on when you're starting out or working on small projects, but simply does not scale. This approach is effectively paving a cowpath that has a sign next to it that reads "hic sunt dracones".
Furthermore, what is the impact here on memory usage when something fundamentally ephemeral like an AJAX request is declared in the DOM as a web component?
If I instantiate a new XHR request in a function scope, the XHR request object gets allocated on the heap. I then typically bind callbacks to the events I care about within the same scope. Again, all are added to the heap because that's how mutable objects are allocated in JavaScript. That function scope eventually returns freeing the variable reference to that XHR object on the stack for that function scope. This XHR object will eventually be available to be garbage collected once all the bound events are fired and the callbacks execute and return. At this point the results have been passed on to their destination and no references should (ideally) remain pointing to the instantiated XHR object. The next time the GC sweeps, it can (theoretically) de-allocate the memory assigned for the XHR request and the memory for the event-bounded callbacks.
With the approach above however, the XHR request is instantiated via a web component and a reference is held indefinitely until either the window is terminated/refreshed or the `polymer-ajax` element is removed from the DOM. I suspect that not only will the memory for the XHR object never be freed, but neither will the memory allocated to the anonymous or named functions bound to the events, since internally the XHR object may still hold a reference to these callbacks (unless the implementation of XHR in question specifically nullifies the reference to callbacks that will never be called again).
We're basically now back at having developers unknowingly performing malloc() in a declarative XML-based syntax, and they are now required to perform free() manually via the removeChild() method on the parent DOM element if they want to get that memory back.
Correction to OP: In Polymer, ajax CAN be an element. Or not. You can build whatever elements you want in Polymer (even non-visual utility elements like xhr and localStorage), but it's YOUR job (the developer) to choose the elements that fit in with the goals and architecture of your project.
Equating the fact that Polymer PROVIDES a declarative ajax element with the inevitability that any project you build will be fraught with bad code factoring and memory bloat because you MUST use it is like saying that because jQuery UI provides a Tab View, all of your jQuery UI's will be horrible because you must build them only out of Tab Views. Polymer just provides the sugar for minting your own custom elements, as well as a solid reference set of pre-built elements (core-, paper-); which ones you choose to use is up to you.
Most of this discussion largely misses the point and elegance of what Web Components generally and Polymer specifically are gunning for: The ability to create, reuse, and share well-factored, arbitrary pieces of web functionality (which may or may not include presentation) that have a well-defined imperative API (instance properties, methods) as well as a familiar, serializable declarative syntax (HTML) that can be manipulated imperatively after the fact (DOM), that will (one day, fingers crossed) be consumed natively by all browsers, without today's existing framework-based silos (React components, Angular directives, etc.). When it makes sense in your application (i.e., when you determine you get more use out of factoring it as a reusable element), then promote that functionality to an element; otherwise, you're free to embed that functionality (including ajax requests) as imperative JavaScript inside the component using the techniques you use today.
As for why you might be interested in a declarative <ajax> element: Polymer also provides declarative property binding and templating, which makes this possible (and absurdly simple, and very cool IMO):
Note from the above example:
- Completely declarative (no imperative JS required)
- No boilerplate querySelectors required
- No boilerplate addEventListeners required
- Good points for readability and understanding author intent
- Are there times where you may need to dynamically create and throw away XHR's based on complex heuristics that don't readily fit into a declarative model like above, or when the maintainability benefits of doing so don't justify whatever (hopefully small) cost there is to instantiating an element and holding it in the DOM while the view is in use vs. using the xhr API imperatively? (rhetorical question: survey says...?)
- In those cases, Polymer doesn't force it's opinion on you that in a lot of cases declarative elements can be good. In those cases, make your xhr calls imperatively like you do today, and apply the component model in the vast majority of other cases where it does make sense.
Time will tell how developers apply this new component model, and Polymer is doing a lot of experimentation in the open to try and push those boundaries and see what sticks.
I'll also add that I was skeptical at first as well. It was only after playing with the actual code for a while that I started to understand, and have actually ported a couple functions over to simple elements.
One of them is an input debouncer. A lot of my UIs lately want to instantly react to the user's actions, but I don't want to fire off a request to the server for every keystroke. The solution is a debouncer, a function or component that takes the input from the user and does something only once the input hasn't changed in some period of time (e.g. there's no sense sending a search request while the user's typing because it will most likely be instantly stale).
So where before I did something like:
onInputChanged(debouncer(function(debouncedInput) {
// a bunch of code to fire off a request to the server
// then render the result back onto the page
}));
"Material design with Polymer" I thought the headline was about a materials design startup, not a UI library. Can you please add more unrelated jargon and nonsensical analogies from random fields to your documentation?
It's very strange that when you click or touch down on a button, the shadow spreads out more, as though the button got further away from the underlying surface. It seems like any "press down" sort of action should, well, make it appear to move down, not up.
Despite all my comments disagreeing strongly with WebComponents and the direction of putting everything in the DOM, I will say that you all did an excellent job with the design aspects of designing for the Z-plane. That's solid stuff and everyone who reads this thread should definitely take the time to read through all the design guidelines for Material, because even if you don't use Material, those ideas are really valuable and can be explored in other frameworks like Famo.us, Ember.js, Velocity.js, React.js. The web is definitely moving in the direction where designing for the Z-plane and subtle animation affordances will matter, and this is great exploration of where things can go.
For those whose experience, is mainly on the web, these are also good resources:
46 comments
[ 4.5 ms ] story [ 109 ms ] threadhttp://imgur.com/AyactvC
https://www.dropbox.com/s/qiqbrs0d55qgf6e/Screenshot%202014-...
But the boilerplate of this system is just too much for me.
Basically, there's a layer of polyfills called the Platform that will disappear as browsers implement key web platform features natively. On top of that is the main Polymer library, which is a small sugaring library that makes using the individual Platform polyfills together a lot easier. On top of that are a couple different sets of both UI and non-UI web components built using Polymer, namely core-elements and paper-elements.
Polymer is tied into the WebComponents standardization effort (also driven by google-related people). Pieces of the DOM are managed by relatively small, contained objects that maintain their own internal state and keep the DOM in sync. It achieves component state synchronization via data binding like Angular or Ember and some sort of KVO mechanism (eventually Object.observe if they're not using that already, I haven't looked at their code in a couple months).
When you write code for React, on the other hand, you basically pretend the DOM is stateless and write your code as if you're writing server side templating code and rendering the entire page from scratch. The framework takes the data structure that the render process builds and efficiently forces the DOM to match what was rendered. At least that's the central concept. There are plenty of caveats.
If anybody has more specific questions, I'm happy to answer them.
I mean, is it possible to do this without sacrificing the benefits of reactjs by simply writing state-ish code in reactjs?
(At first blush, I can't think of a sensible way of doing this...)
[1] http://www.polymer-project.org/docs/polymer/polymer.html#lif...
That said, I don't expect it to be common since you'd basically be building a React component with a Polymer shim and getting almost no leverage out of Polymer. I suppose you could write some code to parse out the html template and turn it into React.DOM equivalents but that seems like a lot of effort.
All React integrations I've seen are the result of introducing React into a legacy codebase or they're using React on a component that's rendering a very large DOM subtree and taking advantage of React's O(N_view) instead of O(N_model) scaling and batched updates for perf wins over current KVO techniques.
You could do the polymer look and feel with the react update model via famo.us (disclaimer: I work for famo.us). Famo.us also plays pretty nicely with Ember.js (tutorials coming soon) and React.js.
Here is Maciej Stachowiak's response to Google's irresponsibility on the intent to ship announcement:
http://lists.w3.org/Archives/Public/www-style/2014Feb/0103.h...
Shoehorning more and much junk into HTML, a markup language with only two types, strings and children, will likely result in bad juju. It may be great for setting things up declaratively, but not for controlling something with state that changes over time. It will serve to reduce what's possible instead of enabling others to explore ideas on the web that are currently only possible in native.
What we need is a low-level retain mode scene graph with a JavaScript API. DOM is a pretty inadequate replacement for a real scene graph. DOM is simply too costly to manipulate and re-arrange and I don't see what WebComponents does to fix that problem.
This might delay the crisis the web feels relative to native, but will just punt the problem a few years down the road at best.
Lastly, some required reading for anyone who wants to educate themselves on the Shadow DOM:
http://acko.net/blog/shadow-dom/
Specifically, where is the code that does the layout for this? I want to see how they are doing the positioning of elements in space. Is it all CSS classes or do they do positioning with javascript?
I have mixed feelings about Polymer, currently its high browser requirements make it too radical to use at work (IE, Firefox & Safari be broken yo), but forward enough to get me experimenting with it on my personal projects. At the workplace, I'll continue to stick to React.
It bugs me that Polymer is being marketed as "polyfills", since the term polyfill generally tends to connote something that fills in for an already agreed upon w3c standard that will appear in all user agents eventually. Whereas web components and shadow dom is still very much in the proposal/experimentation stage and has a ways to go before reaching standardization. There are still some disagreements to be resolved by all those that contribute code to the major user agents.
Calling polymer a polyfills library is misleading and an abuse of the intent of the term polyfill [0].
Also related: "Apple Removes Shadow DOM from Safari"[1][2]
[0] http://remysharp.com/2010/10/08/what-is-a-polyfill/
[1] http://trac.webkit.org/changeset/164131
[2] https://news.ycombinator.com/item?id=7243122
I liked a lot of what I saw in the project, but this "ajax as an element" makes me want to facepalm, or at least scratch my head and wonder "why?!?"
Can someone from the polymer team elaborate the reasoning behind this?
It's not even clear from this example, what is done with the JSON data fetched here. It's not assigned to a variable or returned by a callback. The script below the element in fact uses globals to access the code, since that is basically what `document.querySelector` does. Putting stuff in the DOM is the equivalent of saving all your variables on the window object and then accessing them with `window.myDomElement`, but in a more verbose, indirect and non-performant way.
Furthermore, I noticed in some of the markup elements, the addition of a "url" property. How does "url" differ from "href", especially, when all the examples I saw had URIs pointing to *.html hypertext documents. Is "url" a new property that exists in a standard somewhere? If not, I was under the impression that non-standard HTML properties are supposed to be prefixed.Best thing happend in web in a long time IMHO.
Furthermore, it involves putting data in the DOM (e.g. the `params` property above), where getters and setters now need to go through the inefficient steps of serializing plain old javascript objects when setting a property and parsing a string as a JSON object when getting a JSON property.
This is one of those times, when it's worth asking yourself the question "Hmmmm... putting everything in the DOM... What could possibly go wrong?"The simple fact that the DOM is the only thing that is not accessible to web workers should be a massive red flag. DOM is popular with noobs because it represents global state, which is easy to work on when you're starting out or working on small projects, but simply does not scale. This approach is effectively paving a cowpath that has a sign next to it that reads "hic sunt dracones".
If I instantiate a new XHR request in a function scope, the XHR request object gets allocated on the heap. I then typically bind callbacks to the events I care about within the same scope. Again, all are added to the heap because that's how mutable objects are allocated in JavaScript. That function scope eventually returns freeing the variable reference to that XHR object on the stack for that function scope. This XHR object will eventually be available to be garbage collected once all the bound events are fired and the callbacks execute and return. At this point the results have been passed on to their destination and no references should (ideally) remain pointing to the instantiated XHR object. The next time the GC sweeps, it can (theoretically) de-allocate the memory assigned for the XHR request and the memory for the event-bounded callbacks.
With the approach above however, the XHR request is instantiated via a web component and a reference is held indefinitely until either the window is terminated/refreshed or the `polymer-ajax` element is removed from the DOM. I suspect that not only will the memory for the XHR object never be freed, but neither will the memory allocated to the anonymous or named functions bound to the events, since internally the XHR object may still hold a reference to these callbacks (unless the implementation of XHR in question specifically nullifies the reference to callbacks that will never be called again).
We're basically now back at having developers unknowingly performing malloc() in a declarative XML-based syntax, and they are now required to perform free() manually via the removeChild() method on the parent DOM element if they want to get that memory back.
Equating the fact that Polymer PROVIDES a declarative ajax element with the inevitability that any project you build will be fraught with bad code factoring and memory bloat because you MUST use it is like saying that because jQuery UI provides a Tab View, all of your jQuery UI's will be horrible because you must build them only out of Tab Views. Polymer just provides the sugar for minting your own custom elements, as well as a solid reference set of pre-built elements (core-, paper-); which ones you choose to use is up to you.
Most of this discussion largely misses the point and elegance of what Web Components generally and Polymer specifically are gunning for: The ability to create, reuse, and share well-factored, arbitrary pieces of web functionality (which may or may not include presentation) that have a well-defined imperative API (instance properties, methods) as well as a familiar, serializable declarative syntax (HTML) that can be manipulated imperatively after the fact (DOM), that will (one day, fingers crossed) be consumed natively by all browsers, without today's existing framework-based silos (React components, Angular directives, etc.). When it makes sense in your application (i.e., when you determine you get more use out of factoring it as a reusable element), then promote that functionality to an element; otherwise, you're free to embed that functionality (including ajax requests) as imperative JavaScript inside the component using the techniques you use today.
As for why you might be interested in a declarative <ajax> element: Polymer also provides declarative property binding and templating, which makes this possible (and absurdly simple, and very cool IMO):
Note from the above example: - Completely declarative (no imperative JS required) - No boilerplate querySelectors required - No boilerplate addEventListeners required - Good points for readability and understanding author intent - Are there times where you may need to dynamically create and throw away XHR's based on complex heuristics that don't readily fit into a declarative model like above, or when the maintainability benefits of doing so don't justify whatever (hopefully small) cost there is to instantiating an element and holding it in the DOM while the view is in use vs. using the xhr API imperatively? (rhetorical question: survey says...?) - In those cases, Polymer doesn't force it's opinion on you that in a lot of cases declarative elements can be good. In those cases, make your xhr calls imperatively like you do today, and apply the component model in the vast majority of other cases where it does make sense.Time will tell how developers apply this new component model, and Polymer is doing a lot of experimentation in the open to try and push those boundaries and see what sticks.
One of them is an input debouncer. A lot of my UIs lately want to instantly react to the user's actions, but I don't want to fire off a request to the server for every keystroke. The solution is a debouncer, a function or component that takes the input from the user and does something only once the input hasn't changed in some period of time (e.g. there's no sense sending a search request while the user's typing because it will most likely be instantly stale).
So where before I did something like:
Now I'm doing: This is a toy example, but the long and the short of it is that I'm seeing more code reuse and a much simpler development experience.For those whose experience, is mainly on the web, these are also good resources:
Meaningful Transitions: http://www.ui-transitions.com/
Capptivate: http://capptivate.co/
The Z-Axis - Designing for the Future:
http://alistapart.com/article/the-z-axis-designing-for-the-f...
[disclaimer: I work at famo.us)