Skip to content

Instantly share code, notes, and snippets.

View jquintozamora's full-sized avatar

José Quinto jquintozamora

View GitHub Profile
Promise.resolve().then(function () { return require(/* webpackChunkName: "momentjs" */ "moment"); }).then(function (moment) {
// lazyModule has all of the proper types, autocomplete works,
// type checking works, code references work \o/
var time = moment().format();
console.log("TypeScript >= 2.4.0 Dynamic Import Expression:");
console.log(time);
_this.setState({ time: time });
})
.catch(function (err) {
console.log("Failed to load moment", err);
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
//.... more
}
}
import(/* webpackChunkName: "momentjs" */ "moment")
.then((moment) => {
// lazyModule has all of the proper types, autocomplete works,
// type checking works, code references work \o/
const time = moment().format();
console.log("TypeScript >= 2.4.0 Dynamic Import Expression:");
console.log(time);
this.setState({ time });
})
.catch((err) => {
console.log("*************************************************************");
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser");
console.log("*************************************************************");
const myDocumentsWithCustomObjectAsDocumentsGetParser: any[] = await pnp.sp
.web
.lists
.getByTitle(libraryName)
.items
// using as("Model") overrides select and expand queries
.as(MyDocumentCollection)
console.log("#############################");
console.log("# Query only one document #");
console.log("#############################");
console.log("*************************************************************");
console.log("*** One document selecting all properties");
console.log("*************************************************************");
const myDocument: any = await pnp.sp
.web
.lists
.getByTitle(libraryName)
console.log("*************************************************************");
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser");
console.log("*************************************************************");
const myDocumentsWithCustomObjectAsDocumentsGetParser: any[] = await pnp.sp
.web
.lists
.getByTitle(libraryName)
.items
// using as("Model") overrides select and expand queries
.as(MyDocumentCollection)
console.log("*************************************************************");
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser returning only properties with @select");
console.log("*************************************************************");
const myDocumentsWithCustomObjectAsDocumentsGetParserJustSelect: any[] = await pnp.sp
.web
.lists
.getByTitle(libraryName)
.items
// using as("Model") overrides select and expand queries
.as(MyDocumentCollection)
console.log("*************************************************************");
console.log("*** One document using select, expand and get() with MyDocument Custom Parser");
console.log("*************************************************************");
const myDocumentWithSelectExpandGetParser: any = await pnp.sp
.web
.lists
.getByTitle(libraryName)
.items
.getById(1)
.select("Title", "FileLeafRef", "File/Length")
import { ODataParserBase, QueryableConstructor, Util, Logger, LogLevel } from "sp-pnp-js";
import { getEntityUrl } from "sp-pnp-js/lib/sharepoint/odata";
import { getSymbol } from "../utils/symbol";
/**
* Custom Response Array Parser to be integrated with @select and @expand decorators
* It can be used on PnP Core JS get() method as a parameter
*/
export class SelectDecoratorsArrayParser<T> extends ODataParserBase<T[]> {
// import models
import { MyDocument } from "../model/MyDocument";
import { MyDocumentCollection } from "../model/MyDocumentCollection";
// import pnp js
import pnp from "sp-pnp-js";
console.log("*************************************************************");
console.log("*** Document Collection using as(MyDocumentCollection) and get()");
console.log("*************************************************************");