SlideShare a Scribd company logo
Let’s talk about containers.
Matthew Beale -- @mixonic -- madhatted.com
I build Ember apps for spiffy clients in NYC
Friday, July 12, 13
Friday, July 12, 13
Y’all got issues.
Friday, July 12, 13
Convention over configuration.
Global namespace! So easy!
new App[controllerName+‘Controller’]()
Friday, July 12, 13
• Namespaces are good. Less globals, less conflicts.
• Files map to modules. Could be useful!
• Manage dependencies in JS. Better/simpler build pipeline
and re-usability.
Oh, maybe we should use modules….
Modules for JS
Friday, July 12, 13
THEY’RE COMING
ES6 MODULES
Friday, July 12, 13
Memory management.
Who cares!
Friday, July 12, 13
Friday, July 12, 13
• When do you declare an object un-used?
• What about nested collections of objects?
• How do you reset singletons during tests?
Oh, maybe we should use an Inversion of Control
Container….
Herding objects is hard.
Friday, July 12, 13
Dependencies between objects
Global namespace! So easy!
App.fooController = Ember.Controller.create({
Friday, July 12, 13
• Namespaces are good. Less globals, less conflicts.
App.everythingIsNotASolution
• Often, it will be useful to attach a dependency based on
type.
• Knowing and possibly stubbing dependencies in tests
would be nice.
Oh, maybe we should use Dependency Injection….
Dependencies between objects
Friday, July 12, 13
Friday, July 12, 13
352 PAGES
Friday, July 12, 13
• Factories receive instance variables.
• Resolvers find factories.
• Containers manage injections.
Three Components
Friday, July 12, 13
1 var Factory = Ember.Object.extend();
2
3 // Receives instance variables as a new instance.
4 Factory.create(injections);
5
6 // Can receive injections for future instances.
7 Factory.extend(injections);
8
9
10 // Today in Ember, injections are only sent to instances.
11 // Don't worry yourself about this too much, it may change.
Ember Factories
Friday, July 12, 13
Ember Resolvers
1 Ember.DefaultResolver = Ember.Object.extend({
2 namespace: null,
3
4 resolve: function(fullName) {
5 var parsedName = this.parseName(fullName);
6
7 // Some magic for specific types, but usually getting to:
8 return this.resolveOther(parsedName);
9 },
10
11 resolveOther: function(parsedName) {
12 var className = classify(parsedName.name) + classify(parsedName.type),
13 factory = get(parsedName.root, className);
14 if (factory) { return factory; }
15 }
16 })
Resolves fullNames like controller:application
Must provide `resolve`
Friday, July 12, 13
Ember Containers
1 var container = new Ember.Container();
2
3 container.register('worker:uploader', MyUploader);
4 container.injection('controller', 'uploader', 'worker:uploader');
5
6 container.resolve('worker:uploader'); //=> MyUploader
7 container.lookup('worker:uploader'); //=> instance of MyUploader
8
9 container.lookup('controller:application').get('uploader');
10 //=> same instance of MyUploader
11
12 container.reset();
Friday, July 12, 13
Friday, July 12, 13
In your own app
Thus, `worker` is available on FilePickerController instances
1 var App = Ember.Application.create();
2
3 App.register('worker:uploader', MyUploader);
4 App.inject('controller:filePicker', 'worker', 'worker:uploader');
5
6 // Ah, so simple.
Friday, July 12, 13
In Ember Data
1 Ember.onLoad('Ember.Application', function(Application) {
2 Application.initializer({
3 name: "store",
4
5 initialize: function(container, application) {
6 application.register('store:main', application.Store);
7
8 // Eagerly generate the store so defaultStore is populated.
9 // TODO: Do this in a finisher hook
10 container.lookup('store:main');
11 }
12 });
13
14 Application.initializer({
15 name: "injectStore",
16
17 initialize: function(container, application) {
18 application.inject('controller', 'store', 'store:main');
19 application.inject('route', 'store', 'store:main');
20 }
21 });
22 });
Thus, `store` is available on controllers and routes
Friday, July 12, 13
In your tests
1 Ember.Container.prototype.stub = function(fullName, instance) {
2 instance.destroy = instance.destroy || function() {};
3 this.cache.dict[fullName] = instance;
4 };
5
6 var container;
7
8 module('UserController saves', {
9 setup: function(){ container = App.__container__ }
10 });
11
12 test('is saves', function(){
13 expect(1);
14 container.stub('main:store', function(){
15 this.save = function(){ ok(true) };
16 });
17 controller = container.lookup('controller:user');
18 controller.send('submit');
19 });
Friday, July 12, 13
THEY’RE COMING
ES6 MODULES
Friday, July 12, 13
THEY’RE HERE
ES6 MODULES
EMBER APP KIT
Friday, July 12, 13
In your own app
Thus, `worker` is available on FilePickerController instances
1 var App = Ember.Application.create();
2
3 App.register('worker:uploader', MyUploader);
4 App.inject('controller:filePicker', 'worker', 'worker:uploader');
5
6 // Ah, so simple.
GLOBAL
Flashback to…
Friday, July 12, 13
• Namespaces are good. Less globals, less conflicts.
• Files map to modules. Could be useful!
• Manage dependencies in JS. Better/simpler build pipeline
and re-usability.
Oh, maybe we should use modules….
Modules for JS
Flashback to…
Friday, July 12, 13
https://github.com/stefanpenner/ember-app-kit
Grunt pipeline, es6-module-transpiler
Friday, July 12, 13
1 module "appkit/app" {
2 var App = Ember.Application.create();
3 export default App;
4 // <script type="text/javascript">import App from “appkit/app”;</script>
5 }
6
7 module "appkit/templates/application" {
8 var template = Ember.Handlebars.compile("Howdy Washington!");
9 export default template;
10 }
Real scopes. No globals.
Files become ES6 modules
Friday, July 12, 13
Friday, July 12, 13
Ember Resolvers
1 Ember.DefaultResolver = Ember.Object.extend({
2 namespace: null,
3
4 resolve: function(fullName) {
5 var parsedName = this.parseName(fullName);
6
7 // Some magic for specific types, but usually getting to:
8 return this.resolveOther(parsedName);
9 },
10
11 resolveOther: function(parsedName) {
12 var className = classify(parsedName.name) + classify(parsedName.type),
13 factory = get(parsedName.root, className);
14 if (factory) { return factory; }
15 }
16 })
Resolves fullNames like controller:application
Must provide `resolve`
Flashback to...
IM
PLIES
APP.SOM
ETHING
Friday, July 12, 13
1 module "appkit/app" {
2 var App = Ember.Application.create();
3
4 import applicationTemplate from "appkit/templates/application";
5 Em.TEMPLATES['application'] = applicationTemplate;
6
7 export default App;
8 // <script type="text/javascript">import App from “appkit/app”;</script>
9 }
10
11 module "appkit/templates/application" {
12 var template = Ember.Handlebars.compile("Howdy Washington!");
13 export default template;
14 }
Quick fix...
But do that for everything? No way.
Friday, July 12, 13
• Factories receive instance variables.
• Resolvers find factories.
• Containers manage injections.
Three Components
Flashback to…
OH
HAI
Friday, July 12, 13
80 function resolveOther(parsedName) {
81 var prefix = this.namespace.modulePrefix;
82 Ember.assert('module prefix must be defined', prefix);
83
84 var pluralizedType = typeMap[parsedName.type] || parsedName.type;
85 var name = parsedName.fullNameWithoutType;
86
87 var moduleName = prefix + '/' + pluralizedType + '/' + underscore(name);
88 var module;
89
90 if (define.registry[moduleName]) {
91 module = requireModule(moduleName);
92
93 if (typeof module.create !== 'function') {
94 module = classFactory(module);
95 }
96
97 if (Ember.ENV.LOG_MODULE_RESOLVER){
98 Ember.logger.info('hit', moduleName);
99 }
100
101 return module;
102 } else {
103 if (Ember.ENV.LOG_MODULE_RESOLVER){
104 Ember.logger.info('miss', moduleName);
105 }
106
107 return this._super(parsedName);
108 }
109 }
/vendor/loader.js
Friday, July 12, 13
1 module "appkit/app" {
2 var App = Ember.Application.create();
3 export default App;
4 // <script type="text/javascript">import App from “appkit/app”;</script>
5 }
6
7 module "appkit/templates/application" {
8 var template = Ember.Handlebars.compile("Howdy Washington!");
9 export default template;
10 }
Ember & ES6 modules, no hacks
Friday, July 12, 13
• Views
• Controllers
• Templates
• Routes
Today, works with...
Yay, good-guy classes are fetched via containers
Friday, July 12, 13
• Some Views
• Models
• Helpers
Today, busted with...
Boo, Scumbag classes are not referenced via the container
Friday, July 12, 13
• Subcontainers. Flush only part of the app.
• Singleton controllers live forever. Problem? Feature?
• Ember.Container could become a micro-lib. Uses no
Ember internally.
The future
Friday, July 12, 13
Questions? Ideas?
Matthew Beale - @mixonic - madhatted.com
Friday, July 12, 13

More Related Content

What's hot

Testing view controllers with Quick and Nimble
Testing view controllers with Quick and NimbleTesting view controllers with Quick and Nimble
Testing view controllers with Quick and Nimble
Marcio Klepacz
 
Quick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental SetupQuick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental Setup
Brian Gesiak
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
Visual Engineering
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
Natasha Murashev
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
Natasha Murashev
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
Harikrishnan C
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
Łukasz Kużyński
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cli
Cory Forsyth
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
Alex Eftimie
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
Boris Dinkevich
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
Marco Otte-Witte
 
Excellent
ExcellentExcellent
Excellent
Marco Otte-Witte
 
RSpec
RSpecRSpec
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
Igor Napierala
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
Tim Tyrrell
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
Visual Engineering
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
Boris Dinkevich
 

What's hot (19)

Testing view controllers with Quick and Nimble
Testing view controllers with Quick and NimbleTesting view controllers with Quick and Nimble
Testing view controllers with Quick and Nimble
 
Quick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental SetupQuick: Better Tests via Incremental Setup
Quick: Better Tests via Incremental Setup
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cli
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Excellent
ExcellentExcellent
Excellent
 
RSpec
RSpecRSpec
RSpec
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 

Similar to Ember and containers

Backbone
BackboneBackbone
Backbone
Ynon Perek
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
William Myers
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
Micha Hernandez van Leuffen
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
Rebecca Murphey
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
jimi-c
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
jaxconf
 
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Mike Desjardins
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
William Myers
 
What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...
Richard McIntyre
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
Christian Lilley
 
Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloaded
cbeyls
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
bcoca
 
A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2
Craig Marvelley
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
Ynon Perek
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
Dr Nic Williams
 
Java bad coding practices
Java bad coding practicesJava bad coding practices
Java bad coding practices
Gustavo Carrion, MiT
 

Similar to Ember and containers (20)

Backbone
BackboneBackbone
Backbone
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
 
What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
 
Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloaded
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Java bad coding practices
Java bad coding practicesJava bad coding practices
Java bad coding practices
 

More from Matthew Beale

Ember.js Module Loading
Ember.js Module LoadingEmber.js Module Loading
Ember.js Module Loading
Matthew Beale
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017
Matthew Beale
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
Matthew Beale
 
Ember Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkEmber Community 2016 - Be the Bark
Ember Community 2016 - Be the Bark
Matthew Beale
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
Matthew Beale
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
Matthew Beale
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
Matthew Beale
 
New Component Patterns in Ember.js
New Component Patterns in Ember.jsNew Component Patterns in Ember.js
New Component Patterns in Ember.js
Matthew Beale
 
Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector ember
Matthew Beale
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
Matthew Beale
 
Snappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsSnappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember Apps
Matthew Beale
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.js
Matthew Beale
 

More from Matthew Beale (12)

Ember.js Module Loading
Ember.js Module LoadingEmber.js Module Loading
Ember.js Module Loading
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
Ember Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkEmber Community 2016 - Be the Bark
Ember Community 2016 - Be the Bark
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
New Component Patterns in Ember.js
New Component Patterns in Ember.jsNew Component Patterns in Ember.js
New Component Patterns in Ember.js
 
Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector ember
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
Snappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsSnappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember Apps
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.js
 

Recently uploaded

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 

Recently uploaded (20)

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 

Ember and containers

  • 1. Let’s talk about containers. Matthew Beale -- @mixonic -- madhatted.com I build Ember apps for spiffy clients in NYC Friday, July 12, 13
  • 4. Convention over configuration. Global namespace! So easy! new App[controllerName+‘Controller’]() Friday, July 12, 13
  • 5. • Namespaces are good. Less globals, less conflicts. • Files map to modules. Could be useful! • Manage dependencies in JS. Better/simpler build pipeline and re-usability. Oh, maybe we should use modules…. Modules for JS Friday, July 12, 13
  • 9. • When do you declare an object un-used? • What about nested collections of objects? • How do you reset singletons during tests? Oh, maybe we should use an Inversion of Control Container…. Herding objects is hard. Friday, July 12, 13
  • 10. Dependencies between objects Global namespace! So easy! App.fooController = Ember.Controller.create({ Friday, July 12, 13
  • 11. • Namespaces are good. Less globals, less conflicts. App.everythingIsNotASolution • Often, it will be useful to attach a dependency based on type. • Knowing and possibly stubbing dependencies in tests would be nice. Oh, maybe we should use Dependency Injection…. Dependencies between objects Friday, July 12, 13
  • 14. • Factories receive instance variables. • Resolvers find factories. • Containers manage injections. Three Components Friday, July 12, 13
  • 15. 1 var Factory = Ember.Object.extend(); 2 3 // Receives instance variables as a new instance. 4 Factory.create(injections); 5 6 // Can receive injections for future instances. 7 Factory.extend(injections); 8 9 10 // Today in Ember, injections are only sent to instances. 11 // Don't worry yourself about this too much, it may change. Ember Factories Friday, July 12, 13
  • 16. Ember Resolvers 1 Ember.DefaultResolver = Ember.Object.extend({ 2 namespace: null, 3 4 resolve: function(fullName) { 5 var parsedName = this.parseName(fullName); 6 7 // Some magic for specific types, but usually getting to: 8 return this.resolveOther(parsedName); 9 }, 10 11 resolveOther: function(parsedName) { 12 var className = classify(parsedName.name) + classify(parsedName.type), 13 factory = get(parsedName.root, className); 14 if (factory) { return factory; } 15 } 16 }) Resolves fullNames like controller:application Must provide `resolve` Friday, July 12, 13
  • 17. Ember Containers 1 var container = new Ember.Container(); 2 3 container.register('worker:uploader', MyUploader); 4 container.injection('controller', 'uploader', 'worker:uploader'); 5 6 container.resolve('worker:uploader'); //=> MyUploader 7 container.lookup('worker:uploader'); //=> instance of MyUploader 8 9 container.lookup('controller:application').get('uploader'); 10 //=> same instance of MyUploader 11 12 container.reset(); Friday, July 12, 13
  • 19. In your own app Thus, `worker` is available on FilePickerController instances 1 var App = Ember.Application.create(); 2 3 App.register('worker:uploader', MyUploader); 4 App.inject('controller:filePicker', 'worker', 'worker:uploader'); 5 6 // Ah, so simple. Friday, July 12, 13
  • 20. In Ember Data 1 Ember.onLoad('Ember.Application', function(Application) { 2 Application.initializer({ 3 name: "store", 4 5 initialize: function(container, application) { 6 application.register('store:main', application.Store); 7 8 // Eagerly generate the store so defaultStore is populated. 9 // TODO: Do this in a finisher hook 10 container.lookup('store:main'); 11 } 12 }); 13 14 Application.initializer({ 15 name: "injectStore", 16 17 initialize: function(container, application) { 18 application.inject('controller', 'store', 'store:main'); 19 application.inject('route', 'store', 'store:main'); 20 } 21 }); 22 }); Thus, `store` is available on controllers and routes Friday, July 12, 13
  • 21. In your tests 1 Ember.Container.prototype.stub = function(fullName, instance) { 2 instance.destroy = instance.destroy || function() {}; 3 this.cache.dict[fullName] = instance; 4 }; 5 6 var container; 7 8 module('UserController saves', { 9 setup: function(){ container = App.__container__ } 10 }); 11 12 test('is saves', function(){ 13 expect(1); 14 container.stub('main:store', function(){ 15 this.save = function(){ ok(true) }; 16 }); 17 controller = container.lookup('controller:user'); 18 controller.send('submit'); 19 }); Friday, July 12, 13
  • 23. THEY’RE HERE ES6 MODULES EMBER APP KIT Friday, July 12, 13
  • 24. In your own app Thus, `worker` is available on FilePickerController instances 1 var App = Ember.Application.create(); 2 3 App.register('worker:uploader', MyUploader); 4 App.inject('controller:filePicker', 'worker', 'worker:uploader'); 5 6 // Ah, so simple. GLOBAL Flashback to… Friday, July 12, 13
  • 25. • Namespaces are good. Less globals, less conflicts. • Files map to modules. Could be useful! • Manage dependencies in JS. Better/simpler build pipeline and re-usability. Oh, maybe we should use modules…. Modules for JS Flashback to… Friday, July 12, 13
  • 27. 1 module "appkit/app" { 2 var App = Ember.Application.create(); 3 export default App; 4 // <script type="text/javascript">import App from “appkit/app”;</script> 5 } 6 7 module "appkit/templates/application" { 8 var template = Ember.Handlebars.compile("Howdy Washington!"); 9 export default template; 10 } Real scopes. No globals. Files become ES6 modules Friday, July 12, 13
  • 29. Ember Resolvers 1 Ember.DefaultResolver = Ember.Object.extend({ 2 namespace: null, 3 4 resolve: function(fullName) { 5 var parsedName = this.parseName(fullName); 6 7 // Some magic for specific types, but usually getting to: 8 return this.resolveOther(parsedName); 9 }, 10 11 resolveOther: function(parsedName) { 12 var className = classify(parsedName.name) + classify(parsedName.type), 13 factory = get(parsedName.root, className); 14 if (factory) { return factory; } 15 } 16 }) Resolves fullNames like controller:application Must provide `resolve` Flashback to... IM PLIES APP.SOM ETHING Friday, July 12, 13
  • 30. 1 module "appkit/app" { 2 var App = Ember.Application.create(); 3 4 import applicationTemplate from "appkit/templates/application"; 5 Em.TEMPLATES['application'] = applicationTemplate; 6 7 export default App; 8 // <script type="text/javascript">import App from “appkit/app”;</script> 9 } 10 11 module "appkit/templates/application" { 12 var template = Ember.Handlebars.compile("Howdy Washington!"); 13 export default template; 14 } Quick fix... But do that for everything? No way. Friday, July 12, 13
  • 31. • Factories receive instance variables. • Resolvers find factories. • Containers manage injections. Three Components Flashback to… OH HAI Friday, July 12, 13
  • 32. 80 function resolveOther(parsedName) { 81 var prefix = this.namespace.modulePrefix; 82 Ember.assert('module prefix must be defined', prefix); 83 84 var pluralizedType = typeMap[parsedName.type] || parsedName.type; 85 var name = parsedName.fullNameWithoutType; 86 87 var moduleName = prefix + '/' + pluralizedType + '/' + underscore(name); 88 var module; 89 90 if (define.registry[moduleName]) { 91 module = requireModule(moduleName); 92 93 if (typeof module.create !== 'function') { 94 module = classFactory(module); 95 } 96 97 if (Ember.ENV.LOG_MODULE_RESOLVER){ 98 Ember.logger.info('hit', moduleName); 99 } 100 101 return module; 102 } else { 103 if (Ember.ENV.LOG_MODULE_RESOLVER){ 104 Ember.logger.info('miss', moduleName); 105 } 106 107 return this._super(parsedName); 108 } 109 } /vendor/loader.js Friday, July 12, 13
  • 33. 1 module "appkit/app" { 2 var App = Ember.Application.create(); 3 export default App; 4 // <script type="text/javascript">import App from “appkit/app”;</script> 5 } 6 7 module "appkit/templates/application" { 8 var template = Ember.Handlebars.compile("Howdy Washington!"); 9 export default template; 10 } Ember & ES6 modules, no hacks Friday, July 12, 13
  • 34. • Views • Controllers • Templates • Routes Today, works with... Yay, good-guy classes are fetched via containers Friday, July 12, 13
  • 35. • Some Views • Models • Helpers Today, busted with... Boo, Scumbag classes are not referenced via the container Friday, July 12, 13
  • 36. • Subcontainers. Flush only part of the app. • Singleton controllers live forever. Problem? Feature? • Ember.Container could become a micro-lib. Uses no Ember internally. The future Friday, July 12, 13
  • 37. Questions? Ideas? Matthew Beale - @mixonic - madhatted.com Friday, July 12, 13