fix: add idraw default opts

This commit is contained in:
chenshenhai 2021-07-23 15:58:23 +08:00
parent 686ed54b54
commit 82f7095ae8
4 changed files with 40 additions and 28 deletions

View file

@ -1,7 +1,7 @@
# @idraw/core
* [] License text in JS result
* [] Options default data
* [x] License text in JS result
* [x] Options default data
* [] Support gradient color
* [] Listen keyboard action
* [] Keep all num two decimals

View file

@ -0,0 +1,11 @@
import { PrivateOptions } from './types';
export const defaultOptions: PrivateOptions = {
width: 400,
height: 300,
contextWidth: 400,
contextHeight: 300,
devicePixelRatio: 1,
onlyRender: false,
maxRecords: 10,
}

View file

@ -1,22 +1,9 @@
import Core from '@idraw/core';
import {
TypeData,
TypeCoreOptions,
TypeConfig,
TypeData, TypeConfig,
} from '@idraw/types';
type Options = {
maxRecords?: number;
} & TypeCoreOptions;
type PrivateOptions = {
maxRecords: number;
} & Options;
type Record = {
data: TypeData;
time: number;
}
import { Options, Record, PrivateOptions } from './types';
import { defaultOptions } from './config';
const _opts = Symbol('_opts');
const _doRecords = Symbol('_doRecords');
@ -33,12 +20,12 @@ class IDraw extends Core {
constructor(mount: HTMLDivElement, opts: Options, config?: TypeConfig) {
super(mount, {
width: opts.width,
height: opts.height,
contextWidth: opts.contextWidth,
contextHeight: opts.contextHeight,
devicePixelRatio: opts.devicePixelRatio,
onlyRender: opts.onlyRender
width: opts.width || defaultOptions.width,
height: opts.height || defaultOptions.height,
contextWidth: opts.contextWidth || defaultOptions.contextWidth,
contextHeight: opts.contextHeight || defaultOptions.contextHeight,
devicePixelRatio: opts.devicePixelRatio || defaultOptions.devicePixelRatio,
onlyRender: opts.onlyRender || defaultOptions.onlyRender,
}, config || {});
this[_opts] = this._createOpts(opts);
this[_initEvent]();
@ -109,10 +96,7 @@ class IDraw extends Core {
}
private _createOpts(opts: Options): PrivateOptions {
const defaultOpts = {
maxRecords: 10,
};
return { ...defaultOpts, ...opts };
return { ...defaultOptions, ...opts };
}
}

View file

@ -0,0 +1,17 @@
import {
TypeData,
TypeCoreOptions,
} from '@idraw/types';
export type Options = {
maxRecords?: number;
} & TypeCoreOptions;
export type PrivateOptions = {
maxRecords: number;
} & Options;
export type Record = {
data: TypeData;
time: number;
}