Sunday, September 24, 2017

Reducers versus Effects in the NgRx paradigm

A reducer transforms state and does it synchronously. If you need to run any other sort of code in a similar vein you use an effect, and this could be anything that does not affect state.

Saturday, September 23, 2017

What lends the spread operator in TypeScript to immutability per se?

Well, consider this:

let yin = [13, 42];
let yang = [69, 86];
let yinyang = [...yin, ...yang];
console.log(yinyang);

 
 

It spits this up to the console in Google Chrome Development Tools:

  1. Array(4)
    • 13
    • 42
    • 69
    • 86

 
 

If we expand the code to this:

let yin = [13, 42];
let yang = [69, 86];
let yinyang = [...yin, ...yang];
console.log(yinyang);
yinyang[2] = 0;
console.log(yinyang);
console.log(yang);

 
 

We get this:

  1. Array(4)
    • 13
    • 42
    • 0
    • 86
  2. Array(4)
    • 13
    • 42
    • 0
    • 86
  3. Array(2)
    • 69
    • 86

 
 

And furthermore this:

let yin = [13, 42];
let yang = [69, 86];
let yinyang = [...yin, ...yang];
console.log(yinyang);
yinyang[2] = 0;
console.log(yinyang);
console.log(yang);
yang[0] = 13;
console.log(yinyang);
console.log(yang);

 
 

Gives:

  1. Array(4)
    • 13
    • 42
    • 0
    • 86
  2. Array(4)
    • 13
    • 42
    • 0
    • 86
  3. Array(2)
    • 13
    • 86
  4. Array(4)
    • 13
    • 42
    • 0
    • 86
  5. Array(2)
    • 13
    • 86

 
 

Neato! A change to the arrays' numbers does not affect the values in the other arrays. Now let's try the same trick with some objects:

let yin = {
   foo: 13,
   bar: 42
};
let yang = {
   bar: 69,
   baz: {
      qux: true
   }
};
let yinyang = {
   ...yin,
   ...yang
};
console.log(yinyang);

 
 

What is immediately above gives us:

  1. Object
    • bar: 69
    • baz:
      • qux: true
    • foo: 13

 
 

Alright, so far so good. Now consider this:

let yin = {
   foo: 13,
   bar: 42
};
let yang = {
   bar: 69,
   baz: {
      qux: true
   }
};
let yinyang = {
   ...yin,
   ...yang
};
console.log(yinyang);
yinyang.bar = 86;
yinyang.baz.qux = false;
console.log(yinyang);
console.log(yang);

 
 

Well that yields:

  1. Object
    • bar: 86
    • baz:
      • qux: false
    • foo: 13
  2. Object
    • bar: 86
    • baz:
      • qux: false
    • foo: 13
  3. Object
    • bar: 69
    • baz:
      • qux: false

 
 

Oh no! Trouble in paradise! This kinda works, but the objects that are copied are not deep copied leading to some unexpected behavior. Notice that all qux settings end up as false. What is more...

let yin = {
   foo: 13,
   bar: 42
};
let yang = {
   bar: 69,
   baz: {
      qux: true
   }
};
let yinyang = {
   ...yin,
   ...yang
};
console.log(yinyang);
yinyang.bar = 86;
yinyang.baz.qux = false;
console.log(yinyang);
console.log(yang);
yang.bar = 0;
yang.baz.qux = null;
console.log(yinyang);
console.log(yang);

 
 

Gives us:

  1. Object
    • bar: 86
    • baz:
      • qux: null
    • foo: 13
  2. Object
    • bar: 86
    • baz:
      • qux: null
    • foo: 13
  3. Object
    • bar: 0
    • baz:
      • qux: null
  4. Object
    • bar: 86
    • baz:
      • qux: null
    • foo: 13
  5. Object
    • bar: 0
    • baz:
      • qux: null

Friday, September 22, 2017

There is a distinction between simple and searched case statements in T-SQL.

The searched approach uses conditional operators to arrive at true or false for which branch to take as suggested here. The simple approach is more like a case/switch statement. This has this example which seems to use the AdventureWorks database which is some dummy database that is used in dummy scenarios like the Northwind database.

USE AdventureWorks2012;
GO
SELECT ProductNumber, Category =
      CASE ProductLine
         WHEN 'R' THEN 'Road'
         WHEN 'M' THEN 'Mountain'
         WHEN 'T' THEN 'Touring'
         WHEN 'S' THEN 'Other sale items'
         ELSE 'Not for sale'
      END,
   Name
FROM Production.Product
ORDER BY ProductNumber;
GO

 
 

You may have an OR or an AND in a searched case statement like so:

WHEN Yin > 13 or Yang < 42 THEN 'Meh'

Pull settings out of the columns of a SharePoint list with Nintext tasks to push records back to an MSSQL database.

This is doable. I don't really understand it end to end yet. The markup looks something like so:

UPDATE DeathNotice SET
EffectiveDate = '{ItemProperty:Effective_x0020_Date}',
Explanation = '{ItemProperty:Explanation}',
SupervisorComments = '{ItemProperty:Supervisor_x0020_Comments}',
ContactPhone = '{ItemProperty:Phone}',
IsCompleted = 1
WHERE DeathNoticeID = '{ItemProperty:Death_x0020_Notice_x0020_ID}'

 
 

_x0020_ here represents a space in the name of a column.

npm run whatever

A command line command of "npm run " (assuming you are using Webpack in an Angular 4 app) followed by a keyword as a third word will run the property with the third word's name in the object at the scripts property in package.json at the immediate folder.

Wednesday, September 20, 2017

syntactic sugar for nullable types in C#

What's the difference between...

DateTime? itsYourBirthday = null;

 
 

...and...

Nullable<DateTime> itsYourBirthday = null;

 
 

...in C#? Nothing? There is no difference. This says: "The former is syntactic sugar for the second."

Tuesday, September 19, 2017

If ngModel is used with a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.

This Angular 4 error suggests you are associating an [(ngModel)] with something that is not an attribute. A hierarchical naming drill down will not work here.