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
 
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)Amazon Web Services
 
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
 
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)
AWS re:Invent 2016: Building a Solid Business Case for Cloud Migration (ENT308)
 
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
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

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