RSS

Category Archives: References

ECMAScript 2015 Destructuring and Spread

Destructuring

Destructuring is a way to unpack values from arrays, or properties from objects, into its own variables.

var o = {p: 42, q: true};
var {p: foo, q: bar} = o;

console.log(foo); // 42
console.log(bar); // true

Spread

Spread allows collection to be expanded in places where zero or more arguments are expected (in function), or elements are expected (in array literals), or key-value pairs are expected (in object literals).

function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6

console.log(sum.apply(null, numbers));
// expected output: 6

Reference

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

Advertisements
 
Leave a comment

Posted by on January 10, 2019 in General, References

 

Tags: , , , , ,

NgRx Entity

NgRx Entity

NgRx Entity is a library to handle entity within NgRx framework. The entity in the context is defined as the application’s domain objects, like User, Employee, etc.

The purposes of NgRx Entity are basically:

  • Reduce boilerplate code.
  • Search and sort entities quickly.

The first thing we need to use NgRx Entity is to create an entity adapter, like so:

const adapter = createEntityAdapter();

NgRx Entity also defines `EntityState<>` interface. The interface is also extensible should the additional properties in the application state are needed,

The shape of EntityState is something like this:

interface EntityState {
  ids: string[];
  entities: { [id: string]: V };
}

What this allows us to do is:

  • Find entity quickly using `entities` dictionary.
  • Maintain order of the list, good for use in sorting.

Some boilerplate codes that are reduced when using NgRx Entity:

  • No need to specify properties of the state interface.
  • Add, remove, update of entities in the state are handled by entity adapter.
  • Entity adapter has most commonly used selectors.

Reference

https://medium.com/ngrx/introducing-ngrx-entity-598176456e15

 
Leave a comment

Posted by on December 20, 2018 in General, References

 

Tags: , , , , ,

What is Event Sourcing?

Event Sourcing

Every application has a state, representing current snapshot at the moment. Event sourcing is the idea of persisting all of these states as it changes from one to another.

Imagine a workflow for an invoice goes something like: invoice is created which set the status to pending. Pending invoice then gets approved which sets it approved. Approved invoice can be denied or collected. When invoice is denied, it goes back to pending, but when it’s collected, it becomes closed. The state of an invoice is where it’s at a particular time. However, when event sourcing pattern is implemented, we will be able to see a historical timeline of an invoice, from when it’s created to the current state.

What this allows us to do is, we are able to:

  • Complete rebuild: getting rid of the current state and use events to rebuild the invoice to its current state.
  • Temporal query: we can tell what state an invoice is at particular point in time.
  • Event replay: when the past event is incorrect, we can make the change and compute it from the beginning, thus, replaying the whole series of events.

Some applications of event sourcing are:

  • Source control. Every source control uses time series where commits made change the code. By storing events for every commit, we are able to state of the code at particular point in time.
  • Redo / undo. Applications that utilize undo / redo, such as word processor, will benefit from event sourcing pattern.
  • Document history. Word processor application will also benefit from event sourcing by storing event every time changes are made.

I hope this simple explanation of event sourcing helps you to understand what it is and how we can use it. There’s definitely a lot more to it that I don’t cover here, but there are lots of resources online you can learn from.

Reference

https://martinfowler.com/eaaDev/EventSourcing.html

 
Leave a comment

Posted by on November 29, 2018 in General, References

 

Tags: , , ,

GAC and GACUTIL in a Nutshell

What’s GAC?

Global Assembly Cache.

What’s in the GAC?

See GAC content:

C:\> gacutil -l
or
C:\> gacutil /l
or a specific assembly:
C:\> gacutil -l msshrtmi

Or alternatively, look into the following folders:

.NET Framework 4 and newer: %windir%\Microsoft.NET\assembly.
Earlier versions of the .NET Framework: %windir%\assembly.

Accessing GACUTIL

If you have Visual Studio installed, GACUTIL should be accessible in Visual Studio Developer Command Prompt:

C:\Users\JohnDoe\Source> gacutil

Where’s GACUTIL?

If you don’t have Visual Studio, chances are GACUTIL is not recognized in the command prompt. But it doesn’t mean you don’t have it.

Try look in the following folders:

C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\bin
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools

Or any other version available.

GACUTIL comes with Windows SDK. If you still can’t find, download Windows SDK.

Installing New GAC

C:\> gacutil /i MyLibrary.dll

GACUTIL will place the assembly in the GAC directory based on the version of .NET Framework used to compile the assembly.

You don’t need to restart your computer for the installation to take effect.

References

Global Assembly Cache GAC
GACUTIL
View GAC Content

 
1 Comment

Posted by on January 14, 2018 in References

 

Tags: , , ,

Android Application Lifecycle

android-application-lifecycle

A simplified illustration of the Activity lifecycle, expressed as a step pyramid. This shows how, for every callback used to take the activity a step toward the Resumed state at the top, there’s a callback method that takes the activity a step down. The activity can also return to the resumed state from the Paused and Stopped state.

Source: Android Developer

 
Leave a comment

Posted by on October 16, 2014 in References

 

Tags:

Android Fragment Lifecycle

android-fragment-lifecycle-1
The lifecycle of a fragment (while its activity is running).

android-fragment-lifecycle-2
The effect of the activity lifecycle on the fragment lifecycle.

Source: Android Developer

 
Leave a comment

Posted by on October 15, 2014 in References

 

Tags:

Basic Grunt Commands

Following are some useful commands for Grunt JS, a task runner for JavaScript.

Display Grunt version.

$ grunt --version

Run grunt file (gruntfile.js).

$ grunt
 
Leave a comment

Posted by on October 7, 2014 in References

 

Tags: ,

 
%d bloggers like this: