Saturday, 14 April 2018

React ShouldComponentUpdate with transclude content

Experiment 🙌 @react shouldComponentUpdate with transclude content in parent.

App > Menu > Button > some transclude content from App. If Menu stop update then transclude content also not updated.

https://stackblitz.com/edit/react-ngcontent-with-shoulduptate

Don't block event loop

After i readout Docs about
https://nodejs.org/en/docs/guides/dont-block-the-event-loop/

draw 👀 my understanding

Interesting lines on Docs

  1.  Node is fast when the work associated with each client at any given time is "small".
  2. Node can make do with fewer threads, then it can spend more of your system's time and memory working on clients rather than on paying space and time overheads for threads (memory, context-switching).
  3. Only the Event Loop is allowed to see the "namespace" (JavaScript state) of your application. From a Worker, you cannot manipulate a JavaScript object in the Event Loop's namespace. Instead, you have to serialize and deserialize any objects you wish to share. Then the Worker can operate on its own copy of these object(s) and return the modified object (or a "patch") to the Event Loop.
  4. Node excels for I/O-bound work, but for expensive computation it might not be the best option
  5. Whether you use only the Node Worker Pool or maintain separate Worker Pool(s), you should optimize the Task throughput of your Pool(s). To do this, minimize the variation in Task times by using Task partitioning.


Event Loop in NodeJS

After deep study🕵️ I understand eventloop concept in node . Process.nexttick & setImdiate are interesting 😎. Stack overflow 👩‍💻 helped.

Why NodeJS

Impressive article about : why NodeJs JVM may be a highly performant beast, but Node.js is fast because programmers are forced to write fast programs by not introducing blocking I/O to the program flow.

Saturday, 20 August 2011

Custom Event in AS3


How to create Custom Event?

Following step to show how to create custom event

1.Extend the Event Class of flash.events.Event package

2.Call super() method with the three parameter inside the class constructor

3.Override clone() method for re-dispatch event

3.Override toString() method for trace out the event details

Example: Click the image and get downdload file




Custom Event class is useful for transfer the data from one class to another class using event dispatching concept. In my reference example XmlEvent class is a CustomEvent class. Its pass the signal with data from XmlLoader class to Main class

Saturday, 18 June 2011

Event flow in AS3.0

Flash Player or AIR dispatches event objects whenever an event occurs. If the event target is not on the display list, Flash Player or AIR dispatches the event object directly to the event target. For example, Flash Player dispatches the progress event object directly to a URLStream object. If the event target is on the display list, however, Flash Player dispatches the event object into the display list, and the event object travels through the display list to the event target.
The event flow describes how an event object moves through the display list. The display list is organized in a hierarchy that can be described as a tree. At the top of the display list hierarchy is the Stage, which is a special display object container that serves as the root of the display list. The Stage is represented by the flash.display.Stage class and can only be accessed through a display object. Every display object has a property named stage that refers to the Stage for that application.
When Flash Player or AIR dispatches an event object for a display list-related event, that event object makes a roundtrip journey from the Stage to the target node. The DOM Events Specification defines the target nodeas the node representing the event target. In other words, the target node is the display list object where the event occurred. For example, if a user clicks on a display list object named child1, Flash Player or AIR will dispatch an event object using child1 as the target node.
The event flow is conceptually divided into three parts. The first part is called the capture phase; this phase comprises all of the nodes from the Stage to the parent of the target node. The second part is called the target phase, which consists solely of the target node. The third part is called the bubbling phase. The bubbling phase comprises the nodes encountered on the return trip from the parent of the target node back to the Stage.


Example  of event flow download and see it.


Click




Friday, 10 June 2011

Singleton in AS3

There are some situations where we need to allow only one object to be created for a class. This can be achieved by “Singleton” pattern in as3. We can use the singleton pattern to access a class object globally.

How to prepare a singleton class:-
whenever we want to create a singleton pattern, we should keep two important steps in our mind.
  • We have to block the constructor to restrict instance creations of the class.
  • In order to access that class we should provide one static property

In the following example (SingletonExample.as ), First I have created a singleton class where the constructor has been blocked using throw statement. The throw statement throws an error whenever we tied to create an instance with syntax like var instace:SingletonExample = new SingletonExample();

Example(SingletonExample.as ):-

package
{
public class SingletonExample
{
public function SingletonExample()
{
throw(new Error(“Error: Instantiation failed: You can't instantiate a SingletonExample Class with new keyword”))
}
}
}


var instace:SingletonExample = new SingletonExample();//output: Error: Instantiation failed: You can't instantiate a SingletonExample Class with new keyword


Now we are providing a static property to access SingletonExample class.

Example:-

package
{
private static var _instance:SingletonExample=null
private static var lock:Boolean=true;


public class SingletonExample
{

public static function get instance(): SingletonExample
{
if( _instance==null)
{
lock=false;
_instance=new SingletonExample();
lock=true;
}
return _instance;
}


public function SingletonExample()
{
if(lock)
{throw(new Error(“Error: Instantiation failed: You can't instantiate a SingletonExample Class with new keyword”))}
}
public function message():void
{
trace(“Well Come to Singleton Class”)
}

}// Class closed
} // package closed


By using instance property of the above class we can access the message method as following.

SingletonExample.instance.message()// output panel:- Well Come to Singleton Class



Singleton class vs Static class?
  • The Singleton class object is created only when we make the first call through instance property. Since it uses lazy instantiation it will save memory consumption. Where as in static classes, all static members will consume more system resources and may slow down the startup process of the application.
  • it's easy to re factor . When made the changes from singleton to multiton ('n' of instance) is too easy
  • Static methods and properties cannot be inherited.
You can download the source files from the following link. Feel free to share your thoughts on this.

singleton.rar