Skip to content

Commit

Permalink
pseudo code to show what I'm looking for
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 26, 2016
1 parent 080bac8 commit d032ad5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/index.js
Expand Up @@ -14,7 +14,6 @@ import rimraf from 'rimraf';
import screenshotStream from 'screenshot-stream';
import viewportList from 'viewport-list';
import protocolify from 'protocolify';
import arrayUniq from 'array-uniq';
import filenamifyUrl from 'filenamify-url';
import template from 'lodash.template';
import pify from 'pify';
Expand Down Expand Up @@ -55,11 +54,20 @@ type Viewport = {
keywords: Array<string>;
};

type srcFn<Value> =
& ((_: void) => void) // TODO: should return `this._src`
& ((url: string, sizes: Array<string>, options?: Options) => Value); // TODO: should return `this`

type destFn<Value> =
& ((_: void) => void) // TODO: should return `this._dest`
& ((dir: string) => Value); // TODO: should return `this`

const getResMem = mem(getRes);
const viewportListMem = mem(viewportList);

let listener;
export default class Pageres extends EventEmitter {

export default class Pageres<Value> extends EventEmitter {
/**
* Initialize a new Pageres
*
Expand Down Expand Up @@ -96,9 +104,8 @@ export default class Pageres extends EventEmitter {
* @param {Object} options
* @api public
*/

// src(url?: string, sizes?: Array<string>, options?: Options): Pageres | Array<Src> {
src(url, sizes, options): Pageres | Array<Src> { // TODO: how can I make all the arguments optional or all required? the commented out line doesn't work as it complains it can also be `undefined`. Can I define a separate type definiton for each scenario?
src: srcFn<Value>;
src(url, sizes, options) { // TODO: how can I make all the arguments optional or all required? the commented out line doesn't work as it complains it can also be `undefined`. Can I define a separate type definiton for each scenario?
if (!arguments.length) {
return this._src;
}
Expand All @@ -114,8 +121,8 @@ export default class Pageres extends EventEmitter {
* @param {String} dir
* @api public
*/

dest(dir): Pageres | string { // TODO: is there any way to define retur types based on input?
dest: destFn<Value>;
dest(dir) {
if (!arguments.length) {
return this._dest;
}
Expand Down

0 comments on commit d032ad5

Please sign in to comment.