Skip to content

Commit

Permalink
noEmitHelpers __decorate()
Browse files Browse the repository at this point in the history
  • Loading branch information
GoToLoop committed May 23, 2022
1 parent f43f279 commit f7f704c
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 37 deletions.
1 change: 1 addition & 0 deletions @types/base/globals.d.mts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export declare const CREATE = "create", AUTO = "AutoExpose", INIT = "init", PRE = "pre", POST = "post", REMOVE = "remove", DescriptorsAllTrue: PropertyDescriptor;
export default function __decorate(decors: Function[], o: object, k?: PropertyKey, desc?: PropertyDescriptor): object | undefined;
//# sourceMappingURL=globals.d.mts.map
2 changes: 1 addition & 1 deletion @types/base/globals.d.mts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/classes/ball.d.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* P5js Library Template (v2.0.0)
* P5js Library Template (v2.0.1)
* GoToLoop (2022-Apr-08)
*
* https://Discourse.Processing.org/t/
Expand Down
10 changes: 10 additions & 0 deletions dist/base/globals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ export const CREATE = 'create', AUTO = 'AutoExpose', INIT = 'init', PRE = 'pre',
configurable: true,
enumerable: true
};
// https://GitHub.com/microsoft/tslib
export default function __decorate(decors, o, k, desc) {
const c = arguments.length;
var d, i = decors.length, r = c < 3 ? o : desc !== null ? desc : Object.getOwnPropertyDescriptor(o, k);
while (i--)
if (d = decors[i])
r = (c < 3 ? d(r) : c > 3 ? d(o, k, r) : d(o, k)) || r;
return c > 3 && r && Object.defineProperty(o, k, r), r;
}
globalThis.__decorate ||= __decorate;
8 changes: 1 addition & 7 deletions dist/classes/ball.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* P5js Library Template (v2.0.0)
* P5js Library Template (v2.0.1)
* GoToLoop (2022-Apr-08)
*
* https://Discourse.Processing.org/t/
Expand All @@ -8,12 +8,6 @@
* https://GitHub.com/GoToLoop/P5JS-Library-Template
* https://GoToLoop.GitHub.io/P5JS-Library-Template
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var Ball_1;
import InjectToP5js from "../decorators/p5jsClassInjection.mjs";
let Ball = Ball_1 = class Ball {
Expand Down
12 changes: 6 additions & 6 deletions dist/decorators/p5jsClassInjection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ function InjectToP5js(isP5ParamLast, createPrefix = CREATE, scriptTagAttrName =
return new c(this, ...arguments);
};
globalThis.p5?.prototype.registerMethod(INIT, applyInjections);
function exposeClassGlobally() {
name in globalThis || Object.defineProperty(globalThis, name, {
value: c,
...DescriptorsAllTrue
});
}
function applyInjections() {
if (isGlobalMode() || checkScriptsForAttr(attrib))
exposeClassGlobally();
Expand All @@ -31,5 +25,11 @@ function InjectToP5js(isP5ParamLast, createPrefix = CREATE, scriptTagAttrName =
...DescriptorsAllTrue
});
}
function exposeClassGlobally() {
name in globalThis || Object.defineProperty(globalThis, name, {
value: c,
...DescriptorsAllTrue
});
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "p5js-library-template",
"version": "2.0.0",
"version": "2.0.1",
"description": "Sorta template to develop p5js library addons in TS",
"author": "GoToLoop",
"license": "Unlicense",
Expand Down
22 changes: 22 additions & 0 deletions src/base/globals.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,25 @@ export const
configurable: true,
enumerable: true
};

// https://GitHub.com/microsoft/tslib
export default function __decorate(
decors: Function[],
o: object,
k?: PropertyKey,
desc?: PropertyDescriptor)
{
const c = arguments.length;

var
d: Function,
i = decors.length,
r = c < 3? o : desc !== null? desc : Object.getOwnPropertyDescriptor(o, k!);

while (i--) if (d = decors[i])
r = (c < 3? d(r) : c > 3? d(o, k, r) : d(o, k)) || r;

return c > 3 && r && Object.defineProperty(o, k!, r), r;
}

globalThis.__decorate ||= __decorate;
2 changes: 1 addition & 1 deletion src/classes/ball.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* P5js Library Template (v2.0.0)
* P5js Library Template (v2.0.1)
* GoToLoop (2022-Apr-08)
*
* https://Discourse.Processing.org/t/
Expand Down
18 changes: 9 additions & 9 deletions src/decorators/p5jsClassInjection.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function InjectToP5js(
function InjectToP5js(
isP5ParamLast?: boolean | Class,
createPrefix = CREATE,
scriptTagAttrName = AUTO) {

scriptTagAttrName = AUTO)
{
if (typeof isP5ParamLast == 'function') InjectClassDecor(isP5ParamLast);
else return InjectClassDecor; // @InjectToP5js()

Expand All @@ -41,13 +41,6 @@ function InjectToP5js(

globalThis.p5?.prototype.registerMethod(INIT, applyInjections);

function exposeClassGlobally() {
name in globalThis || Object.defineProperty(globalThis, name, {
value: c,
...DescriptorsAllTrue
});
}

function applyInjections(this: p5) {
if (isGlobalMode() || checkScriptsForAttr(attrib)) exposeClassGlobally();

Expand All @@ -56,5 +49,12 @@ function InjectToP5js(
...DescriptorsAllTrue
});
}

function exposeClassGlobally() {
name in globalThis || Object.defineProperty(globalThis, name, {
value: c,
...DescriptorsAllTrue
});
}
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"declarationMap": true,
"inlineSourceMap": false,
"importHelpers": false,
"noEmitHelpers": false,
"noEmitHelpers": true,
"listEmittedFiles": true,
"experimentalDecorators": true,
"strict": true
Expand Down
24 changes: 14 additions & 10 deletions typings/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as p5 from "p5"
import * as p5 from "p5"
import decorate from "../src/base/globals.mjs"

type P5RegTypes = 'init' | 'pre' | 'post' | 'remove'

Expand All @@ -8,18 +9,21 @@ type Class<T = object> = {
}

declare global {
var p5: {
new (sketch?: (p: p5) => void, nodevt?: HTMLElement | string): p5
var
__decorate: typeof decorate,

VERSION: string
instance: p5
disableFriendlyErrors: typeof p5.prototype.disableFriendlyErrors
p5: {
new (sketch?: (p: p5) => void, nodevt?: HTMLElement | string): p5

prototype: p5 & {
registerMethod(register: P5RegTypes, callback: (this: p5) => void): void
registerPreloadMethod(name: PropertyKey, proto: object): void
VERSION: string
instance: p5
disableFriendlyErrors: typeof p5.prototype.disableFriendlyErrors

prototype: p5 & {
registerMethod(register: P5RegTypes, callback: (this: p5) => void): void
registerPreloadMethod(name: PropertyKey, proto: object): void
}
}
}

function preload(this: p5): void
function setup(this: p5): void
Expand Down

0 comments on commit f7f704c

Please sign in to comment.