SlideShare a Scribd company logo
1 of 38
Download to read offline
Rich Object Models &
Angular
Ben Teese, Shine Technologies
Overview
Why?
Loading Data
Adding Business Logic
Advanced Stuff
Most of the apps I build are

CRUD
...it was nice
WARNING
The remainder of this presentation
contains UX that some viewers may find
disturbing
Proposal
Internal
Currency
NonRecurring
Engineering

External
Currency

Customer

Shipsets

External
Cost Items

Material
Cost Items

Internal
Cost Items

Customer
Type

Cost

Cost

Department

Sales Price
Override

Currency

Currency

OMG

Recurring
Engineering

Details

Years

Line
Replaceable
Unit

Currency

Customer
Type Prices
External Cost
Items

Internal Cost
Item

Subassemblies

Standard
Sales Price

Spare Parts
Sales Price
Customer
Type

Cost

Department

Supplier

Purchase Price
Ranges

Currency

Sales Price

Currency
Currency

Currency

Purchase Price

Currency
Restangular
Getting Stuff
// GET /proposals
Restangular.all('proposals').getList().then(
function(proposals) {
$scope.proposals = proposals;
}
);
or...
// GET /proposals
$scope.proposals =
Restangular.all('proposals').getList().
$object;
Getting Nested Stuff
// GET /proposals/:id/cost_items
$scope.proposal.getList('cost_items').then(
function(costItems) {
$scope.costItems = costItems;
}
);
Rich Models
angular.module('pimpMyPlane.services', ['restangular']).
factory('ProposalSvc', function(Restangular) {
Restangular.extendModel('proposals', function(obj) {
return angular.extend(obj, {!
profit: function() {
return this.revenue().minus(this.cost());
},
revenue: function() {
return this.price().
convertTo(this.internalCurrency);
}
...
});
});
return Restangular.all('proposals');
})
A Model Mixin
angular.module('pimpMyPlane.models').
factory('Proposal', function() {
return {
profit: function() {
return this.revenue().minus(this.cost());
},
revenue: function() {
return this.price().
convertTo(this.internalCurrency);
},
...
};
}
Using the Mixin
angular.module('pimpMyPlane.services',
['restangular', 'pimpMyPlane.models']
).factory('ProposalSvc', function(Restangular, Proposal){
Restangular.extendModel('proposals', function(obj) {
return angular.extend(obj, Proposal);
});
return Restangular.all('proposals');
});
What about nested models?
angular.module('pimpMyPlane.services', ['restangular']).
factory('ProposalSvc', function(Restangular) {
Restangular.extendModel('proposals', function(obj) {
angular.extend(obj.recurringEngineering, {
...
});
angular.extend(obj.nonRecurringEngineering, {
...
});
angular.extend(obj.internalCurrency, { ... });
angular.extend(obj.externalCurrency, { ... });
return angular.extend(obj, Proposal);
});
...
})
Introduce mixInto()
angular.module('pimpMyPlane.services',
['restangular', 'pimpMyPlane.models']
).
factory('Proposals', function(Restangular, Proposal) {
Restangular.extendModel('proposals', function(obj) {
return Proposal.mixInto(obj);
});
...
});
angular.module('pimpMyPlane.models').
factory('Proposal', function(
Currency, RecurringEngineering, NonRecurringEngineering
) {
return {
mixInto: function(obj) {
RecurringEngineering.mixInto(
obj.recurringEngineering
);
NonRecurringEngineering.mixInto(
obj.nonRecurringEngineering
);
Currency.mixInto(obj.internalCurrency);
Currency.mixInto(obj.externalCurrency))
return angular.extend(obj, this);
},
profit: function() {
return this.revenue().minus(this.cost());
},
...
};
});
Proposal
Internal
Currency
NonRecurring
Engineering

External
Currency

Customer

Recurring
Engineering

Shipsets

External
Cost Items

Material
Cost Items

Internal
Cost Items

Customer
Type

Cost

Cost

Department

Sales Price
Override

Currency

Currency

Details

Years

Line
Replaceable
Unit

Currency

Customer
Type Prices
External Cost
Items

Internal Cost
Item

Subassemblies

Standard
Sales Price

Spare Parts
Sales Price
Customer
Type

Cost

Department

Supplier

Purchase Price
Ranges

Currency

Sales Price

Currency
Currency

Currency

Purchase Price

Currency
Shazam
Identity Maps
Proposal
Internal
Currency
NonRecurring
Engineering

External
Currency

Customer

Recurring
Engineering

Shipsets

External
Cost Items

Material
Cost Items

Internal
Cost Items

Customer
Type

Cost

Cost

Department

Sales Price
Override

Currency

Currency

Details

Years

Line
Replaceable
Unit

Currency

Customer
Type Prices
External Cost
Items

Internal Cost
Item

Subassemblies

Standard
Sales Price

Spare Parts
Sales Price
Customer
Type

Cost

Department

Supplier

Purchase Price
Ranges

Currency

Sales Price

Currency
Currency

Currency

Purchase Price

Currency
Identity Map
“currency”:1

EUR

“currency”:2
...

USD
...

“department”:1

Finance

“department”:2

IT

...

...
Mapping Nested Currencies
angular.module('pimpMyPlane.models').
factory('Money', function(Currency, identityMap) {
return {
mixInto: function(obj) {
obj.currency = identityMap(
'currency',
Currency.mixInto(obj.currency)
);
angular.extend(object, this);
},
...
});
Mapping RESTful Currencies
angular.module('pimpMyPlane.services',
['restangular', 'pimpMyPlane.models']
).factory('CurrenciesSvc', function(
Restangular, Currency, identityMap
) {
Restangular.extendModel('currencies', function(obj){
return identityMap(
'currency', Currency.mixInto(obj)
);
});
return Restangular.all('currencies');
});
Getter Functions
(Uniform Access Principle)
angular.module('pimpMyPlane.models').
factory('Proposal', function(extendWithGetters) {
return {
mixInto: function(obj) {
...
return extendWithGetters(obj, this);
},
get profit() {
return this.revenue.minus(this.cost);
},
get revenue() {
return this.price.convertTo(
this.internalCurrency
);
},
...
};
}
);
Memoization
angular.module('pimpMyPlane.models').
factory('Proposal', function(Model) {
return Model.extend({
memoize: ['revenue', 'cost'],
...
get profit() {
return this.revenue.minus(this.cost);
},
get revenue() {
return this.price.convertTo(
this.internalCurrency
);
},
...
};
}
);
Unmemoization
<div ng-controller="ProposalCtrl">
...
<input type="number"
ng-model="currency.conversionFactor"
ng-change="proposal.unmemoize()"></input>
...
<table>
<tr>
<td>Number of Aircraft</td>
<td>
<input type="number" min="1"
ng-model="proposal.numberOfAircraft"
ng-change="proposal.unmemoize()"></input>
</td>
</tr>
</table>
</div>
Computed Properties
angular.module('pimpMyPlane.models').
factory('Proposal', function(...) {
return Model.extend({
...
computedProperties: {
profit: [function() {
return this.revenue.minus(this.cost);
}, 'revenue', 'cost'],
cost: [function() {
return this.recurringEngineering.cost.plus(
this.nonRecurringEngineering.cost
);
}, 'recurringEngineering.cost',
'nonRecurringEngineering.cost']
},
});
});
...needs more work
Let’s Wrap This Up
Shrink-wrapped
Boeing 737
Rich Models can work
Identity Maps
Getters, Memoization
Computed properties
Please enjoy the remainder of your flight

@benteese

More Related Content

Similar to Rich Object Models & Angular.js

Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And TricksJulie Lerman
 
O365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingO365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingRiwut Libinuko
 
Fall 09 Residential Presentation
Fall 09 Residential PresentationFall 09 Residential Presentation
Fall 09 Residential Presentationkneadae
 
Application Frameworks an Experience Report
Application Frameworks an Experience ReportApplication Frameworks an Experience Report
Application Frameworks an Experience ReportESUG
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2Hammad Rajjoub
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2Hammad Rajjoub
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDDKonstantin Kudryashov
 
computerscience-170129081612.pdf
computerscience-170129081612.pdfcomputerscience-170129081612.pdf
computerscience-170129081612.pdfKiranKumari204016
 
Automatic Code Generation
Automatic Code GenerationAutomatic Code Generation
Automatic Code Generationelliando dias
 
Value engineering and Analysis
Value engineering and AnalysisValue engineering and Analysis
Value engineering and AnalysisChaitanya Chenna
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Codemotion Dubai
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesRachel Reese
 
Project Cost Proposal PowerPoint Presentation Slides
Project Cost Proposal PowerPoint Presentation SlidesProject Cost Proposal PowerPoint Presentation Slides
Project Cost Proposal PowerPoint Presentation SlidesSlideTeam
 

Similar to Rich Object Models & Angular.js (20)

Oop cocepts
Oop coceptsOop cocepts
Oop cocepts
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
 
O365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingO365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side Rendering
 
Fall 09 Residential Presentation
Fall 09 Residential PresentationFall 09 Residential Presentation
Fall 09 Residential Presentation
 
Application Frameworks an Experience Report
Application Frameworks an Experience ReportApplication Frameworks an Experience Report
Application Frameworks an Experience Report
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDD
 
ACH 216 Lecture 04a (Estimating)
ACH 216 Lecture 04a (Estimating)ACH 216 Lecture 04a (Estimating)
ACH 216 Lecture 04a (Estimating)
 
CRUD with Dojo
CRUD with DojoCRUD with Dojo
CRUD with Dojo
 
computerscience-170129081612.pdf
computerscience-170129081612.pdfcomputerscience-170129081612.pdf
computerscience-170129081612.pdf
 
Automatic Code Generation
Automatic Code GenerationAutomatic Code Generation
Automatic Code Generation
 
Value engineering and Analysis
Value engineering and AnalysisValue engineering and Analysis
Value engineering and Analysis
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservices
 
Project Cost Proposal PowerPoint Presentation Slides
Project Cost Proposal PowerPoint Presentation SlidesProject Cost Proposal PowerPoint Presentation Slides
Project Cost Proposal PowerPoint Presentation Slides
 
mean stack
mean stackmean stack
mean stack
 
Angularjs
AngularjsAngularjs
Angularjs
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Rich Object Models & Angular.js

Editor's Notes

  1. UX is important Journeyman developer Rails I Like Angular
  2. Journeyman developer Rails I Like Angular
  3. Alternatives Nested