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
AOP with FeathersJS
Search
AbraaoAlves
September 04, 2016
Programming
1
250
AOP with FeathersJS
Show a powerful and flexible way to create API services in NodeJS.
AbraaoAlves
September 04, 2016
Tweet
Share
More Decks by AbraaoAlves
See All by AbraaoAlves
React+Redux+Typescript
abraaoalves
0
100
Other Decks in Programming
See All in Programming
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
4
2k
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
310
OTP を自動で入力する裏技
megabitsenmzq
0
130
モダンOBSプラグイン開発
umireon
0
180
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
4.3k
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.2k
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
450
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.1k
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
140
飯MCP
yusukebe
0
380
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.6k
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
170
Being A Developer After 40
akosma
91
590k
Mobile First: as difficult as doing things right
swwweet
225
10k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
410
The Cult of Friendly URLs
andyhume
79
6.8k
From π to Pie charts
rasagy
0
160
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
230
Abbi's Birthday
coloredviolet
2
5.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Transcript
Aspect Oriented Programming with FeathersJS
Why Aspect?
Why Aspect ... var express = require('express'); var app =
express(); app.update('/', function (req, res, next) { if (isLoggedln(req) && isValidate(req)) { getUser(req.params.userId).then(function (user) { if (isAdmin(user) && isCurrent(user)) { updateInfo(req).then(function (info) { if (info.emailme) { sendEmail(user.email, info) } removePassword(user); res.send(info); }) } }); } }); because systems grow
@abraao4lves Software Engennier abraaoalves.github.io
Inspiration: Functional Programming f(g(x))
Continuation–passing style (CPS)
Continuation–passing style (CPS) let createUser = validateRequest >> verifyEmail >>
db.createUser >> smtpServer.sendEmail >> returnMessage F# Example:
(CPS) with NodeJS ?
var express = require('express'); var bodyParser = require('body-parser'); var app
= express(); app .use(bodyParser.json()) .use(function (req, res, next) { getUser(req.params.userId).then(function(user){ req.body.username = user.name; next() }) }) .use(function (req, res) { res.json(req.body || {message:'No content'}) }) (CPS) with NodeJS! Express - Middlewares
var express = require('express'); var bodyParser = require('body-parser'); var app
= express(); app .use(bodyParser.json()) .use(function (req, res, next) { getUser(req.params.userId).then(function(user){ req.body.username = user.name; next() }) }) .use(function (req, res) { res.json(req.body || {message:'No content'}) }) (CPS) with NodeJS! Express - Middlewares
And ... Aspect Oriented Programming?
Aspect Oriented Programming!
None
Get Starter
(CPS) with FeathersJS
(CPS) with FeathersJS // Register the hooks app.service('users') .before({ find:
[isLoggedIn, isAdmin], get: [isLoggedIn, isCurrent], create: hashPassword }) .after(removePasswords) .after({ create: sendEmail });
(CPS) with FeathersJS // Register the hooks app.service('users') .before({ find:
[isLoggedIn, isAdmin], get: [isLoggedIn, isCurrent], create: hashPassword }) .after(removePasswords) .after({ create: sendEmail });
(CPS) with FeathersJS // Register the hooks app.service('users') .before({ find:
[isLoggedIn, isAdmin], get: [isLoggedIn, isCurrent], create: hashPassword }) // To all methods .after(removePasswords) .after({ create: sendEmail });
DEMO
Thanks. @abraao4lves abraaoalves.github.io