From 06ad72c6bb14167c426f59869bab7360378f1b89 Mon Sep 17 00:00:00 2001 From: Stefan Eckert Date: Sat, 17 Aug 2019 00:18:19 +0200 Subject: [PATCH] feat(vector): continue prepare code for docs --- src/index.js | 6 ++++- src/point.js | 64 +++++++++++++++++++++++++++++++++++++++------------ src/vector.js | 51 +++++++++++++++++++++++++++++----------- 3 files changed, 92 insertions(+), 29 deletions(-) diff --git a/src/index.js b/src/index.js index e81c0055..2e344b61 100644 --- a/src/index.js +++ b/src/index.js @@ -16,10 +16,14 @@ export { /** * @param {() => number} alg - * @return {(Vector | Victor | IVector | Point | IPoint) & number} + * @return {(Vector | Victor | IVector | Point | IPoint) & number | number} */ export function calc(alg) { return operatorCalc(alg); } export default Vector; + +export const Export = { + Vector, Victor, IVector, Point, IPoint +}; diff --git a/src/point.js b/src/point.js index e01019c8..a5774e81 100644 --- a/src/point.js +++ b/src/point.js @@ -11,6 +11,7 @@ import formatNumber from './formatter'; /* eslint class-methods-use-this: 0 */ /* eslint-disable no-unused-vars */ +/* eslint-disable no-dupe-keys */ const X = 0; const Y = 1; @@ -56,6 +57,7 @@ class APoint { /** * @param {number | (Alg)} x * @param {number} [y] + * @hidden */ constructor(x, y) { if (typeof x === 'function') { @@ -147,14 +149,14 @@ class APoint { /** * @param {(point: APointType) => number} alg * @returns {this} - * @throws NotImplementedError + * @throws NotImplementedError ⚠ */ calc(alg) { throw new Error('calc() not implemented'); } /** - * @throws NotImplementedError + * @throws NotImplementedError ⚠ * @returns {APoint} */ clone() { @@ -272,8 +274,14 @@ cachedGetter(APoint, 'lengthSq'); /** * Point * + * **constructor** + * ___ * new Point(x: *number*, y: *number*): [[Point]] * + * + * + * **constructor** + * ___ * new Point(alg: (*function*(): *number*)): [[Point]] * */ @@ -329,6 +337,8 @@ export class Point extends APoint { /** * IPoint * + * **constructors** + * ___ * new IPoint(x: *number*, y: *number*): [[IPoint]] * * new IPoint(alg: (*function*(): *number*)): [[IPoint]] @@ -346,6 +356,7 @@ export class IPoint extends APoint { /** * @param {Alg} alg * @return {PointType | IPointType} + * @hidden */ export function calc(alg) { return operatorCalc(alg); @@ -354,29 +365,52 @@ export function calc(alg) { const pointFactory = cachedFactory(Point); /** - * *function* point(x: *number*, y: *number*): [[Point]] & *number* - * - * *function* point(alg: (*function*(): *number*)): [[Point]] & *number* - * * @typedef {(alg: Alg) => PointType} PointAlg * @typedef {(x: number , y: number) => PointType} PointCon - * @typedef {PointAlg & PointCon} + * @typedef {PointAlg & PointCon} point + * @type {point} + * @hidden */ -export const point = function point(x, y) { +export function point(x, y) { return pointFactory(x, y); -}; +} const ipointFactory = cachedFactory(IPoint); /** - * *function* ipoint(x: *number*, y: *number*): [[IPoint]] & *number* - * - * *function* ipoint(alg: (*function*(): *number*)): [[IPoint]] & *number* - * * @typedef {(alg: Alg) => IPointType} IPointAlg * @typedef {(x: number , y: number) => IPointType} IPointCon * @typedef {IPointAlg & IPointCon} -*/ -export const ipoint = function ipoint(x, y) { + * @hidden + */ +export function ipoint(x, y) { return ipointFactory(x, y); +} + +export const Export = { + /** + * @param {Alg} alg + * @return {PointType | IPointType} + */ + calc: alg => operatorCalc(alg), + + /** + * @type {PointAlg} + */ + point: alg => pointFactory(alg), + + /** + * @type {PointCon} + */ + point: (x, y) => pointFactory(x, y), + + /** + * @type {IPointAlg} + */ + ipoint: alg => ipointFactory(alg), + + /** + * @type {IPointCon} + */ + ipoint: (x, y) => ipointFactory(x, y) }; diff --git a/src/vector.js b/src/vector.js index 4f0ce6b6..2342b2a9 100644 --- a/src/vector.js +++ b/src/vector.js @@ -12,6 +12,7 @@ import { ipoint } from './point'; /* eslint class-methods-use-this: 0 */ /* eslint-disable no-unused-vars */ +/* eslint-disable no-dupe-keys */ const X = 0; const Y = 1; @@ -45,6 +46,7 @@ class AVector { } } + /** * @returns {number} */ @@ -191,7 +193,7 @@ class AVector { /** * @param {(vector: AVectorType) => number} arg * @returns {this} - * @throws NotImplementedError + * @throws NotImplementedError ⚠ */ calc(arg) { throw new Error('calc() not implemented'); @@ -199,7 +201,7 @@ class AVector { /** * - * @throws NotImplementedError + * @throws NotImplementedError ⚠ * @return {AVectorType} */ clone() { @@ -462,6 +464,7 @@ export class Victor extends AVector { /** * @param {Alg} alg * @return {VectorType | VictorType} + * @hidden */ export function calc(alg) { return operatorCalc(alg); @@ -470,29 +473,51 @@ export function calc(alg) { const vectorFactory = cachedFactory(Vector); /** - * *function* vector(x: *number*, y: *number*, z: *number*): [[Vector]] & *number* - * - * *function* vector(alg: (*function*(): *number*)): [[Vector]] & *number* - * * @typedef {(alg: Alg) => VectorType} VectorAlg * @typedef {(x: number , y: number, z: number) => VectorType} VectorCon * @typedef {VectorAlg & VectorCon} + * @hidden */ -export const vector = function vector(x, y, z) { +export function vector(x, y, z) { return vectorFactory(x, y, z); -}; +} const victorFactory = cachedFactory(Victor); /** - * *function* victor(x: *number*, y: *number*, z: *number*): [[Victor]] & *number* - * - * *function* victor(alg: (*function*(): *number*)): [[Victor]] & *number* - * * @typedef {(alg: Alg) => VictorType} VictorAlg * @typedef {(x: number , y: number, z: number) => VictorType} VictorCon * @typedef {VictorAlg & VictorCon} + * @hidden */ -export const victor = function victor(x, y, z) { +export function victor(x, y, z) { return victorFactory(x, y, z); +} + +export const Export = { + /** + * @param {Alg} alg + * @return {VectorType | VictorType} + */ + calc: alg => operatorCalc(alg), + + /** + * @type {VectorAlg} + */ + vector: alg => vectorFactory(alg), + + /** + * @type {VectorCon} + */ + vector: (x, y) => vectorFactory(x, y), + + /** + * @type {VictorAlg} + */ + victor: alg => victorFactory(alg), + + /** + * @type {VictorCon} + */ + victor: (x, y) => victorFactory(x, y) };