SlideShare a Scribd company logo
ExtJS Ext.util.Observable By Aaron Conran
Observer Design Pattern An  observable  object can notify any number of  observers  who would like to know  when  an event happens and  what  happened.
Ext.util.Observable To create an Observable Class in Ext inherit from Ext.util.Observable Use the inherited addEvents method to define events in the constructor Ex: var  MyObservable =  function () { this .addEvents({event1:  true ,   event2:  true }); }; Ext.extend(MyObservable, Ext.util.Observable);
Ext.util.Observable The MyObservable class inherits the following methods by inheriting Ext.util.Obserable: addEvents addListener – shorthand of on fireEvent hasListener purgeListener removeListener – shorthand of un
Observers Observers  can  subscribe  to the  Observable  object at any time by adding an event handler. var myObservable = new MyObservable(); myObservable.on(‘event1’, function() {console.log(‘event1 ran!’);});
Ext.util.Observable Observers  can also  unsubscribe  at any time. var myObservable = new MyObservable(); myObservable.on(‘event1’, function() {console.log(‘event1 ran!’);}); myObservable.un(‘event1’, function() {console.log(‘event1 ran!’);}); console.log(myObservable.hasListener(‘imaginary’));
Firing Events By firing events an  observable  class can notify its  observers  that a particular event and provide them with relevant information by arguments. Ex: this.fireEvent(‘event1’, relevantInfo, moreInfo);
Consuming Events Match method signature to the additional arguments that were fired. In this case, relevantInfo and moreInfo Then setup an event handler for this method myCallback : function(relevantInfo, moreInfo) { // use relevantInfo and moreInfo to act accordingly } myObservable.on(‘event1’, myCallback, scope);
Ext.util.Observable  Static Methods Ext.util.Observable has 2 static methods capture (Observable o, Function fn, [Object scope]) releaseCapture (Observable o) Capture is often useful to view the events which are firing and the order in which they fire
Capturing Events Here is a utility function to log the event names to the console of any observable object function  captureEvents(observable) { Ext.util.Observable.capture(observable, function (eventName) { console.log(eventName); },  this ); } // then to use it… captureEvents(myObservable); Firebug Output:
ObservableStack Create the following class: ObservableStack is a simple stack data structure which can be observed. Events of: push : (Array stack, Mixed node) pop : (Array stack, Mixed node) Methods of: push : function(node) pop : function()
ObservableStack.js var  ObservableStack =  function () { this .stack =  new  Array(); this .addEvents({push:  true ,   pop:  true }); }; Ext.extend(ObservableStack, Ext.util.Observable, { push :  function (node) { this .stack.push(node); this .fireEvent('push',  this .stack, node); }, pop :  function () { var  node =  this .stack.pop(); this .fireEvent('pop',  this .stack, node); } });
Example of ObservableStack Ext.onReady( function () { var  obsStack =  new  ObservableStack(); console.log('setting up event handlers'); obsStack.on('push',  function (stack, node) { console.log('Value of : ' + node + ' pushed onto the stack.'); }); obsStack.on('pop',  function (stack, node) { console.log('Value of : ' + node + ' popped off of the stack.'); }); console.log('about to push onto stack..'); obsStack.push(5); obsStack.push(4); obsStack.pop(); console.log('done!'); }); Firebug Output:
ObservableStack Uses By creating an ObservableStack we can update multiple parts of a UI or communicate to multiple classes at the same time! This way they always keep in sync with each other. ExtJS contains a powerful  observable  data structure Ext.util.MixedCollection which maintains both numeric indexes and keys.

More Related Content

PDF
Data binding in AngularJS, from model to view
PPTX
Scope.js prsentation
PPT
Design patterns - Observer Pattern
PPT
Ext Js Events
PPT
Observer and Decorator Pattern
PPTX
Reacting with ReactiveUI
PDF
How to use redux with react hooks in react native application
PDF
React new features and intro to Hooks
Data binding in AngularJS, from model to view
Scope.js prsentation
Design patterns - Observer Pattern
Ext Js Events
Observer and Decorator Pattern
Reacting with ReactiveUI
How to use redux with react hooks in react native application
React new features and intro to Hooks

What's hot (19)

PPTX
PPTX
Design Pattern - Observer Pattern
PPTX
Promises, promises, and then observables
PPTX
Knockoutjs Part 2 Beginners
PDF
JS Anti Patterns
PDF
Introduction to RxJS
PPTX
PPTX
V33 date function-c
KEY
openFrameworks 007 - events
PDF
Deep Dive into React Hooks
PPTX
Dynamic databinding
DOCX
How to handle Dynamic Objects with OpKey?
PDF
Declarative presentations UIKonf
DOCX
Button tambah
PPTX
Rxjs swetugg
PDF
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
PDF
A Series of Fortunate Events - Symfony Camp Sweden 2014
PDF
The Ring programming language version 1.7 book - Part 85 of 196
PPTX
Database connectivity in python
Design Pattern - Observer Pattern
Promises, promises, and then observables
Knockoutjs Part 2 Beginners
JS Anti Patterns
Introduction to RxJS
V33 date function-c
openFrameworks 007 - events
Deep Dive into React Hooks
Dynamic databinding
How to handle Dynamic Objects with OpKey?
Declarative presentations UIKonf
Button tambah
Rxjs swetugg
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
The Ring programming language version 1.7 book - Part 85 of 196
Database connectivity in python
Ad

Similar to Ext J S Observable (20)

PPT
Ext oo
DOCX
Android accelerometer sensor tutorial
PPT
Graphical User Interface (GUI) - 2
PDF
Js objects
PDF
The Ring programming language version 1.7 book - Part 16 of 196
PPTX
Event handling
PPTX
Chapter 11.5
PDF
The Ring programming language version 1.6 book - Part 15 of 189
PPT
event handling new.ppt
PPTX
event-handling.pptx
PDF
Pointer Events Working Group update / TPAC 2023 / Patrick H. Lauke
PDF
2011 07-hiyoko
PDF
Signalsで Event処理を簡単に
PPT
CSharp_04_Events-in-C#-introduction-with-examples
PPT
Os3 2
PPT
PDF
Saving lives with rx java
PPTX
Event Handling PRESENTATION AND PROGRAMMING
PDF
Trisha gee concurrentprogrammingusingthedisruptor
PDF
Unit-3 event handling
Ext oo
Android accelerometer sensor tutorial
Graphical User Interface (GUI) - 2
Js objects
The Ring programming language version 1.7 book - Part 16 of 196
Event handling
Chapter 11.5
The Ring programming language version 1.6 book - Part 15 of 189
event handling new.ppt
event-handling.pptx
Pointer Events Working Group update / TPAC 2023 / Patrick H. Lauke
2011 07-hiyoko
Signalsで Event処理を簡単に
CSharp_04_Events-in-C#-introduction-with-examples
Os3 2
Saving lives with rx java
Event Handling PRESENTATION AND PROGRAMMING
Trisha gee concurrentprogrammingusingthedisruptor
Unit-3 event handling
Ad

More from jason hu 金良胡 (20)

PPT
新员工培训
PDF
Javascript 闭包
PDF
Windows Powershell En
PDF
正则表达式
PDF
Work In Japan
PDF
Linuxcommand
PDF
PDF
Asp.Net运行时
PDF
PDF
PPT
Sql2005 Xml
PDF
Ms Ajax Dom Element Class
PDF
Ms Ajax Dom Element Class
PDF
Ms Ajax Number And Error Extensions
PDF
Ms Ajax Dom Event Class
PDF
Ms Ajax Date And Boolean Extensions
PDF
Ms Ajax Array Extensions
PDF
Ms Ajax String And Object Extensions
PPT
Ext Js Events
PPT
Ext Js Dom Navigation
新员工培训
Javascript 闭包
Windows Powershell En
正则表达式
Work In Japan
Linuxcommand
Asp.Net运行时
Sql2005 Xml
Ms Ajax Dom Element Class
Ms Ajax Dom Element Class
Ms Ajax Number And Error Extensions
Ms Ajax Dom Event Class
Ms Ajax Date And Boolean Extensions
Ms Ajax Array Extensions
Ms Ajax String And Object Extensions
Ext Js Events
Ext Js Dom Navigation

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Teaching material agriculture food technology

Ext J S Observable

  • 2. Observer Design Pattern An observable object can notify any number of observers who would like to know when an event happens and what happened.
  • 3. Ext.util.Observable To create an Observable Class in Ext inherit from Ext.util.Observable Use the inherited addEvents method to define events in the constructor Ex: var MyObservable = function () { this .addEvents({event1: true , event2: true }); }; Ext.extend(MyObservable, Ext.util.Observable);
  • 4. Ext.util.Observable The MyObservable class inherits the following methods by inheriting Ext.util.Obserable: addEvents addListener – shorthand of on fireEvent hasListener purgeListener removeListener – shorthand of un
  • 5. Observers Observers can subscribe to the Observable object at any time by adding an event handler. var myObservable = new MyObservable(); myObservable.on(‘event1’, function() {console.log(‘event1 ran!’);});
  • 6. Ext.util.Observable Observers can also unsubscribe at any time. var myObservable = new MyObservable(); myObservable.on(‘event1’, function() {console.log(‘event1 ran!’);}); myObservable.un(‘event1’, function() {console.log(‘event1 ran!’);}); console.log(myObservable.hasListener(‘imaginary’));
  • 7. Firing Events By firing events an observable class can notify its observers that a particular event and provide them with relevant information by arguments. Ex: this.fireEvent(‘event1’, relevantInfo, moreInfo);
  • 8. Consuming Events Match method signature to the additional arguments that were fired. In this case, relevantInfo and moreInfo Then setup an event handler for this method myCallback : function(relevantInfo, moreInfo) { // use relevantInfo and moreInfo to act accordingly } myObservable.on(‘event1’, myCallback, scope);
  • 9. Ext.util.Observable Static Methods Ext.util.Observable has 2 static methods capture (Observable o, Function fn, [Object scope]) releaseCapture (Observable o) Capture is often useful to view the events which are firing and the order in which they fire
  • 10. Capturing Events Here is a utility function to log the event names to the console of any observable object function captureEvents(observable) { Ext.util.Observable.capture(observable, function (eventName) { console.log(eventName); }, this ); } // then to use it… captureEvents(myObservable); Firebug Output:
  • 11. ObservableStack Create the following class: ObservableStack is a simple stack data structure which can be observed. Events of: push : (Array stack, Mixed node) pop : (Array stack, Mixed node) Methods of: push : function(node) pop : function()
  • 12. ObservableStack.js var ObservableStack = function () { this .stack = new Array(); this .addEvents({push: true , pop: true }); }; Ext.extend(ObservableStack, Ext.util.Observable, { push : function (node) { this .stack.push(node); this .fireEvent('push', this .stack, node); }, pop : function () { var node = this .stack.pop(); this .fireEvent('pop', this .stack, node); } });
  • 13. Example of ObservableStack Ext.onReady( function () { var obsStack = new ObservableStack(); console.log('setting up event handlers'); obsStack.on('push', function (stack, node) { console.log('Value of : ' + node + ' pushed onto the stack.'); }); obsStack.on('pop', function (stack, node) { console.log('Value of : ' + node + ' popped off of the stack.'); }); console.log('about to push onto stack..'); obsStack.push(5); obsStack.push(4); obsStack.pop(); console.log('done!'); }); Firebug Output:
  • 14. ObservableStack Uses By creating an ObservableStack we can update multiple parts of a UI or communicate to multiple classes at the same time! This way they always keep in sync with each other. ExtJS contains a powerful observable data structure Ext.util.MixedCollection which maintains both numeric indexes and keys.