Skip to content

Instantly share code, notes, and snippets.

In AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application.
AngularJS has about 30 built-in services. One of them is the $location service.
The $location service has methods which return information about the location of the current web page:
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
AngularJS provides filters to transform data:
1. currency: Format a number to a currency format.
2. date: Format a date to a specified format.
3. filter: Select a subset of items from an array.
4. json: Format an object to a JSON string.
5. limitTo: Limits an array/string, into a specified number of elements/characters.
6. lowercase: Format a string to lower case.
7. number: Format a number to a string.
8. orderBy: Orders an array by an expression.
The content fields for business and presentation logic all live in Interface Templates –
never in Page Type templates or Datasource Templates. Therefore, these content fields live with the logic that use them
1. Project Layer - The Project layer provides the context of the solution.
This means the actual cohesive website or channel output from the implementation,
such as the page types, layout and graphical design.
It is on this layer that all the features of the solution are stitched together into a cohesive solution that fits the requirements.
Least stable layer
***Project layer adheres to "Stable Dependencies Principle" ***
2. Feature layer- contains concrete features of the solution as understood by the business owners and editors of the solution,
The architecture pattern described by Helix is often referred to as Component-based Architecture or Modular Architecture.
Your template is the data model which your Sitecore items will instantiate, and
your Rendering is a reference to the code you’re writing in Visual Studio that brings that data to the page.
/*Unary function */
function unary(fn){
return function unaryDecorator(first){
return fn.call(this, first);
}
}
Getting functions to work together is function composition.
const uppercaseString = (string) => string.toUpperCase();
const reverseString = (string) => string.split("").reverse().join("");
const upperAndReverseName = (string) => {
const upperCasedName = uppercaseString(name);
return reverseString(upperCasedName);
};
Functions can be data too !!!
Pass them as data like boolean, number, string and Array.
const isEven = (num) => num % 2 === 0; // here "function" is assigned to variable "isEven"
const result = [1, 2, 3, 4].filter(isEven); // here function "isEven" is passed as an argument.
console.log({ result }); // { result: [ 2, 4 ] }
***A function that takes and/or returns another function is called a higher-order function.
It’s “higher-order” because it operates on functions besides basic data types.***
A function must pass two tests to be considered “pure”.
1. Same inputs always return same outputs
const add = (x, y) => x + y;
add(2, 4); // 6
2. No side-effects
A few examples of side-effects are:
1. Mutating your input
2. console.log