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
93
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Pragmatic Web Components
Pragmatic RESTful APIs mixed with Web Components for a flexible frontend development.
Nicolas Mérouze
February 04, 2014
More Decks by Nicolas Mérouze
See All by Nicolas Mérouze
Table-Driven Testing
nmerouze
0
82
Make Hypermedia APIs in Ruby
nmerouze
4
450
Netty with JRuby (French)
nmerouze
2
250
Other Decks in Programming
See All in Programming
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
580
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
110
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.5k
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.5k
AIで効率化できた業務・日常
ochtum
0
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
180
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
2
610
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Are puppies a ranking factor?
jonoalderson
1
3.6k
Technical Leadership for Architectural Decision Making
baasie
3
420
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Building Applications with DynamoDB
mza
96
7.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
KATA
mclloyd
PRO
35
15k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Thoughts on Productivity
jonyablonski
76
5.2k
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