🚧 Wrestling with TypeScript
This commit is contained in:
parent
f4d2785972
commit
2dbebb87d6
7 changed files with 16 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
export class Attributes {
|
||||
list: any = {};
|
||||
|
||||
constructor(init) {
|
||||
constructor(init?) {
|
||||
for (let key in init) {
|
||||
let val = init[key];
|
||||
this.add(key, val);
|
||||
|
|
18
lib/hooks.ts
18
lib/hooks.ts
|
@ -7,17 +7,6 @@ export class Hooks {
|
|||
this.all = ['preRenderSvg', 'postRenderSvg'];
|
||||
}
|
||||
|
||||
///** Add hook */
|
||||
//on(hook, method): void {
|
||||
// // This gets called from the pattern context
|
||||
// // so 'this' is not actually this class
|
||||
// let self = this.hooks;
|
||||
// if(typeof self._hooks[method] === 'undefined') {
|
||||
// self._hooks[hook] = [];
|
||||
// }
|
||||
// self._hooks[hook].push(method);
|
||||
//}
|
||||
|
||||
list(hook): function[] {
|
||||
if(typeof this._hooks[hook] === 'undefined') {
|
||||
return false;
|
||||
|
@ -26,13 +15,6 @@ export class Hooks {
|
|||
return this._hooks[hook];
|
||||
}
|
||||
|
||||
attachPre (hook: string, obj: object): void {
|
||||
this._attach('pre', hook, obj);
|
||||
}
|
||||
attachPost (hook: string, obj: object): void {
|
||||
this._attach('post', hook, obj);
|
||||
}
|
||||
|
||||
attach (hook: string, obj: object): void {
|
||||
if(typeof this._hooks[hook] === 'undefined') return;
|
||||
for(let func of this._hooks[hook]) {
|
||||
|
|
|
@ -26,7 +26,7 @@ export class Part {
|
|||
return this;
|
||||
}
|
||||
|
||||
macroRunner(args) {
|
||||
macroRunner(args?) {
|
||||
let self = this;
|
||||
let data = args;
|
||||
let method = function (key, data) {
|
||||
|
|
|
@ -64,6 +64,7 @@ export class Pattern {
|
|||
render(): string {
|
||||
this.hooks.attach('preRenderSvg', this.svg);
|
||||
this.hooks.attach('postRenderSvg', this.svg);
|
||||
//this.hooks.attach('insertText', this.svg);
|
||||
|
||||
return this.svg.render(this);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export class Point {
|
|||
}
|
||||
|
||||
/** Adds an attribute. This is here to make this call chainable in assignment */
|
||||
attr(name, value): Point {
|
||||
attr(name: string, value: string): Point {
|
||||
this.attributes.add(name, value);
|
||||
|
||||
return this;
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
export type context = {
|
||||
settings: {[propName: string]: any};
|
||||
options: {[propName: string]: any};
|
||||
values: {[propName: string]: any};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
/*
|
||||
export type PatternOptionType = "measure" | "percentage" | "angle" | "choice" | "constant";
|
||||
|
||||
export interface PatternOption {
|
||||
|
@ -63,3 +71,4 @@ declare namespace Pattern {
|
|||
[propName: string]: any;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { Part } from './part'
|
||||
import { Point } from './point'
|
||||
import {context} from './types'
|
||||
|
||||
/** Rounds a value to PRECISION */
|
||||
export function round(value: number): number {
|
||||
|
@ -70,7 +72,7 @@ export function beamCrossesY(from: Point, to: Point, y: number) {
|
|||
}
|
||||
|
||||
/** Returns an object with shorthand access for pattern design */
|
||||
export function shorthand(part, context): {} {
|
||||
export function shorthand(part: Part, context: context): {} {
|
||||
let final = (context.settings.mode === 'draft') ? true : false;
|
||||
let paperless = (context.settings.paperless === true) ? true : false;
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue