In my previous blog, I shared a generic REST library that we can use for the SharePoint CRUD operations and we can also expand that library as needed.
So today, we are going to talk about generic libraries for SharePoint SPFx framework, a latest release from Microsoft for the web part model.
SPFx uses the node.js platform for developing and compiling application/web parts and I also hear many people talking about how a person should learn this framework and it's true.
But, as a professional developer, for many of us it’s hard to spent time on this or consider a different scenario, where we have to develop SPFx web part/applications under tight deadlines.
Well, in such cases, we should think of the resources that we can re-use to quickly develop any application.
SharePoint SPFx framework follows a TypeScript development pattern which enables concepts of OOP. Now, here, we need to think that, at the end, Type Scripts is converted to Java Script, so the browser can execute it.
Most, important, any Java Script frameworks (Angular, knockout, etc) are built to reduce the developer’s efforts. So, if you know the Java Script, you can work on any of these frameworks easily and keeping this in mind, I have converted my previous REST library in TypeScript format.
So, we can re-use existing code in Type Script as well. This library is in partial TypeScript format. The aim of creating SPFx generic library is to enable the developer to quickly start development with SPFx using TypeScript.
I assume that you have working knowledge of creating SPFx application solutions. So, we will not discuss this in this blog.
Files are the same from my previous blog but this time extension is “.ts”.
- ListManager.ts - This file is used to specify list columns we are working with
- ListUtility.ts - This file contains all generic methods
- Utility.ts - It can be used to specify constants as well as utility methods
Only change is, here I have converted JavaScript modules to class to quickly adopt TypeScript pattern.
So, now let’s discuss, how to use this library.
NOTE
In your SPFx project/solution, do not forgot to include jQuery reference.