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.

Slides:



Advertisements
Similar presentations
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Advertisements

Exceptions and Exception Handling Carl Alphonce CSE116 March 9, 2007.
Data Structures - Stacks. What are data structures? Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey)
Data Structures Michael J. Watts
Data Structures & Algorithms
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Runtime Environments Source language issues Storage organization
 2000 Prentice Hall, Inc. All rights reserved. Chapter 22 - C++ Templates Outline 22.1Introduction 22.2Class Templates 22.3Class Templates and Non-type.
Object-Oriented Analysis and Design
ExtJS Classes By Aaron Conran. Creating Classes Creating classes in JavaScript is easy as creating a constructor function and using the new keyword when.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
JAVASCRIPT Introduction Kenny Lam. What is Javascript?  Client-side scripting language that can manipulate elements in the DOM  Event-driven language.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
Team May12-25 Alex Wilkins Kevin Wells Daniel Mears Le Uong Interactive GUI for Emergency Light Bar Design.
Recursion Examples Fundamentals of CS Case 1: Code /* Recursion: Case 1 */ #include void count (int index); main () { count (0); getchar(); } void count.
1 CSC241: Object Oriented Programming Lecture No 13.
Stacks. An alternative storage structure for collections of entities is a stack. A stack is a simplified form of a linked list in which all insertions.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Data Structures and Algorithms Stacks. Stacks are a special form of collection with LIFO semantics Two methods int push( Stack s, void *item ); - add.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Navigating the DOM with ExtJS By Aaron Conran. Document Object Model The Document Object Model or DOM is a standard to represent HTML, XHTML and other.
Lexi case study (Part 2) Presentation by Matt Deckard.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Built-in Data Structures in Python An Introduction.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
C++ How to Program, 9/e © by Pearson Education, Inc. All Rights Reserved.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 12 - Templates Outline 12.1Introduction 12.2Function Templates 12.3Overloading Template Functions.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Dimiter Kunchev.  JavaScript library written by Sam Stephenson   Adds object oriented techniques  Provides.
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
ExtJS Events By Aaron Conran. Events Events describe when a certain action happens. This could be a user action, a response to an Ajax call, etc. Events.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 22 - C++ Templates Outline 22.1Introduction.
TEMPLATESTEMPLATES BCAS,Bapatla B.mohini devi. Templates Outline 22.1Introduction 22.2Class Templates 22.3Class Templates and Non-type Parameters 22.4Templates.
BY: JAKE TENBERG & CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.
Model View ViewModel Architecture. MVVM Architecture components.
 2000 Deitel & Associates, Inc. All rights reserved. 12.1Introduction Templates - easily create a large range of related functions or classes –function.
Chapter 22 - C++ Templates Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =
chap10 Chapter 10 Recursion chap10 2 Recursive Function recursive function The recursive function is a kind of function that calls.
Click to edit Master text styles Stacks Data Structure.
How to Leverage Java in Oracle Forms Web Applications Duncan Mills Application Development Tools Oracle Corporation.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Unit 2. Constructors It initializes an object when it is created. It has same as its class and syntactically similar to a method. Constructor have no.
POINTERS AND MEMORY ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =
Stacks II David Lillis School of Computer Science and Informatics
Adding Fractions.
Delegates and Events 14: Delegates and Events
C# Event Processing Model
Parameter Passing Actual vs formal parameters
JavaScript CS 4640 Programming Languages for Web Applications
Corresponds with Chapter 5
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

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.