Optional Chaining in JavaScript

Optional chaining is in stage 1 and can be found in this repo. Optional Chaining provides a succinct way to check for the existence of an object before accessing its properties.  2_bgVery similar to the C# null conditional operator. And it is already available in the React ecosystem.

Why do we need this?

How often are we checking for existence of an object after an API call? Yes, almost always requiring us to write code like this to prevent errors due to JavaScript’s nature of allowing unstructured anonymous objects. Continue reading “Optional Chaining in JavaScript”

Codemash 2018 – Chrome Dev Tools

Rick Herrmann
I had the good fortune to be able to attend the Codemash Conference again this year. Since the conference started more than 10 years ago, I have only missed it twice. As in past years, there were a number of good sessions over the four days of the conference. Over the next few weeks I will be blogging about a few of them. To start with, I want to talk about the session I attended on Chrome Dev Tools by Greg Malcolm (@gregmalcolm).

Continue reading “Codemash 2018 – Chrome Dev Tools”

Form Validation and Custom Save Functionality in the Standard SharePoint List Form

Mike BerrymanI have a client that needs to log any interactions with their customers in SharePoint.  This client is proficient enough with SharePoint that they feel perfectly comfortable modifying lists in order to add or remove fields to accommodate their needs without having to go through us.  They are regularly adding new fields to this log list in order to capture some new piece of relevant information that it was decided they needed.  This is important background because when they approached me to create a way for them to generate multiple log entries from one “New Item” SharePoint List Form, I knew I couldn’t just create a custom “New Item” form to accomplish this or they would lose the ability to add new fields without having to either modify this custom “New Item” form, or involve us to make those modifications.

So I had to come up with a solution that would retain the standard “New Item” form (so any fields added/removed from the list would be reflected in the form) but would allow for the user to create an entry in their logs for every customer selected in the form.

Continue reading “Form Validation and Custom Save Functionality in the Standard SharePoint List Form”

Managing Content for Similar SharePoint Sites

Mike BerrymanI have a client that has over 50 subsites of the root site in a SharePoint site collection that are all pretty much the same.  There’s a site for each county in the client’s state, each one with web parts to show some data from the root site that’s relevant to that specific county (contacts’ information, documents, that kind of thing).  Whenever they wanted to make a change to, say, the contacts web part for these county site, they had to modify over fifty copies of the same web part.  Tedious to say the least.  After a few rounds of making these kind of repetitious modifications it was decided that I would need to come up with a solution to make managing this stuff much easier.

So I did.

Continue reading “Managing Content for Similar SharePoint Sites”

Inject Scripts in SharePoint with JavaScript

Mike BerrymanDon’t worry, it’s the good kind of Script Injection!

I was recently working in a SharePoint environment where I wanted to have some JavaScript libraries (like jQuery and moment.js) available across the entire site collection.  The most obvious solution would be to add a reference to each library into the master page(s) used across the sites in the site collection but for this situation editing any master page was not an option.  Instead I wanted to use User Custom Actions to do script injection.

Continue reading “Inject Scripts in SharePoint with JavaScript”

Decorators in TypeScript

3Decorators are an experimental feature of TypeScript and, to an extent, of JavaScript itself. They are a concept borrowed from Python, and a way to modify classes using higher order functionality.

The idea is that you pass the class/function/attribute through a function and the result becomes the class/function/attribute.

As an example, if you make a @final decorator and have the code…

Continue reading “Decorators in TypeScript”

Mocking Time with sinon.js

Rick HerrmannI was writing some tests for an Angular app and ran into a scenario where I needed a page to behave differently if the time of day was before or after 6AM.  The logic is simple enough to capture in my controller:

vm.date = moment().subtract(6, 'hours').toDate();

Basically, if it is before 6AM, display the prior day, otherwise display today. However, as I was trying to write a test for this controller the problem came up: how do I take control of the current time to test both scenarios?

Continue reading “Mocking Time with sinon.js”