Posts

Showing posts from March, 2012

JavaScript [ExtJs3]: Total “Record” count in filtered store

There is two way to get record count from the Store store.getTotalCount() This function depend on server response value. For accuracy of the value, property shell if return by the server. Property name for the diff. reader: totalProperty for JsonReader , totalRecords for XmlReader store.getCount() Will return you the number of record from the store. Or if you have filter on the store, it will give you the number of filtered record. But if you want to get the total number of record regardless filtering, Then it will be like this var totalRecords = store.snapshot ? store.snapshot.length : store.getCount(); “snapshot” is the variable in “Store” which hold the actual data in case if you have applied a filter.

JavaScript: Experimenting with Conditional Statement

When conditional statement in your application grow to 30 lines or more, then it’s time for code refactoring. Conditional statements are un-avoidable but JavaScript functional programming behavior gives you really good way to handle such kind of scenario.  Just take a scenario where you have to write a function which return sound for the given animal. var soundOf = function(animal){ var sound; if(animal === 'dog'){ sound = 'bark'; } else if(animal === 'duck'){ sound = 'quack quack'; } else if(animal === 'owl'){ sound = 'hoot'; } else { sound = 'animal not found!!!'; } return sound; } Now think, what your code look like when you have to support 100 animal !!! And same will be true for switch-case statement var soundOf = function(animal){ var sound; switch(animal){ case 'dog': sound = 'bark'; break; case 'duck': sound = 'quack quack'; break; case &#

JavaScript Design Patterns

If you are a big fan of Design Pattern and want to know how to apply those on your JavaScript Application. Then you must read this article. http://addyosmani.com/resources/essentialjsdesignpatterns/book/ Few design pattern from above article Creational Pattern Constructor Pattern Singleton Pattern Module Pattern Revealing Module Pattern Observer Pattern Mediator Pattern Prototype Pattern Command Pattern DRY Pattern Facade Pattern Factory Pattern Mixin Pattern Decorator Pattern