Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Pragmatic Web Components
Search
Nicolas Mérouze
February 04, 2014
Programming
1
82
Pragmatic Web Components
Pragmatic RESTful APIs mixed with Web Components for a flexible frontend development.
Nicolas Mérouze
February 04, 2014
Tweet
Share
More Decks by Nicolas Mérouze
See All by Nicolas Mérouze
Table-Driven Testing
nmerouze
0
67
Make Hypermedia APIs in Ruby
nmerouze
4
440
Netty with JRuby (French)
nmerouze
2
230
Other Decks in Programming
See All in Programming
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
170
Datadog RUM 本番導入までの道
shinter61
1
310
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
150
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
830
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
330
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
4
1k
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
250
GoのWebAssembly活用パターン紹介
syumai
3
10k
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
120
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
120
Featured
See All Featured
Embracing the Ebb and Flow
colly
86
4.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
The Invisible Side of Design
smashingmag
299
51k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
We Have a Design System, Now What?
morganepeng
53
7.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Transcript
Pragmatic Web Components
Web Component ?
Make your own HTML elements
Reuse code
Pragmatic ?
Hypermedia/Pragmatic APIs
Let the API do the work
Example: Pagination
Rails Way
gem 'kaminari'
class PostsController < ApplicationController def index @posts = Post.page(params[:page]) end
end
<%= @posts.total_count %> résultats <%= paginate @posts %>
30 résultats < Prev Next >
API + React.js
gem 'active_model_serializers'
class PostSerializer < ActiveModel::Serializer attributes :id, :title, :body end
{ "posts": [{ "id": "1", "title": "foobar", "body": "such foobar"
}] }
class PostsController < ApplicationController def index page = (params[:page] ||
1).to_i @posts = Post.page(page) pagination = { totalCount: @posts.total_count } pagination[:next] = posts_url(page: page + 1) unless page == @posts.total_pages pagination[:prev] = posts_url(page: page - 1) unless page == 1 render json: @posts, meta: { pagination: pagination } end end
{ "meta": { "pagination": { "totalCount": 30, "next": "http://localhost:3000/posts?page=3", "prev":
"http://localhost:3000/posts?page=1" } } "posts": [{ "id": "1", "title": "foobar", "body": "such foobar" }] }
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pragmatic Web Components</title>
</head> <body> <div id="pagination"></div> </body> </html>
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pragmatic Web Components</title>
<script src="//fb.me/JSXTransformer-0.8.0.js"></script> <script src="//fb.me/react-0.8.0.js"></script> </head> <body> <div id="pagination"></div> <script type="text/jsx"> /** @jsx React.DOM */ React.renderComponent(<Paginaton/>, document.getElementById('pagination')); </script> </body> </html>
<script type="text/jsx"> /** @jsx React.DOM */ var Paginaton = React.createClass({
render: function() { return ( <div> <div>{this.state.totalCount} résultats</div> <div> <a href={this.state.prev} onClick={this.prevPage}>‹ Prev</a> <a href={this.state.next} onClick={this.nextPage}>Next ›</a> </div> </div> ); } }); </script>
<script type="text/jsx"> /** @jsx React.DOM */ var Paginaton = React.createClass({
getInitialState: function() { return { totalCount: 0, next: null, prev: null }; }, // render }); </script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></ script> <script type="text/jsx"> /** @jsx React.DOM */ var
Paginaton = React.createClass({ componentDidMount: function() { this.fetchPosts("/posts"); }, fetchPosts: function(url) { var self = this; $.getJSON(url, function(data) { var pagination = data.meta.pagination; self.setState({ totalCount: pagination.totalCount, next: pagination.next, prev: pagination.prev }); }); }, prevPage: function(e) { this.fetchPosts(this.state.prev); return false; }, nextPage: function(e) { this.fetchPosts(this.state.next); return false; }, // getInitialState, render }); </script>
30 résultats < Prev Next >
More features: link component, display posts
Apply everywhere
Forms (Validations, Errors, Search)
Breadcrumbs, Flashes, Tabs, Tables
Web Components standard http://w3.org/TR/components-intro
React.js http://facebook.github.io/react
x-tags http://x-tags.org
polymer http://polymer-project.org
Ember.js http://ember.js
What we saw today?
Web Components are simple and usable today
More information in your API == less code for the
frontend
Rails is great for APIs with ActiveModel::Serializers
Nicolas Mérouze http://merouze.me
In-App Cloud http://inappcloud.com