How to use paramTag method in storybook-root

Best JavaScript code snippet using storybook-root

envelope_editor_view.ts

Source:envelope_editor_view.ts Github

copy

Full Screen

1import {addKnob, IParameterControl} from "./controls";2import * as Model from "../model/sidebands_model";3import {ParamTag, ParseTag, TargetTag} from "../model/sidebands_model";4import {MakeEnvelopeEditor, MakeGraphicalEnvelopeEditor} from "./templates";5import {GD, GeneratorView} from "./views";6import {controller, IDependent, IParameter, IRangeParameter, ValueOf} from "../model/vst_model";7export class EnvelopeEditorKnobView implements GeneratorView {8 controls: Array<IParameterControl>;9 constructor(readonly element: HTMLDivElement, private gennum: number, target: Model.TargetTag) {10 this.controls = [];11 const targetPrefix = Model.TargetTag[target].toString().toLowerCase();12 let panel = MakeEnvelopeEditor(targetPrefix);13 element.appendChild(panel);14 this.makeEnvelopeKnobs(targetPrefix, gennum, target);15 }16 updateSelectedGenerator(gennum: number): void {17 for (let control of this.controls) {18 control.updateSelectedGenerator(gennum);19 }20 this.gennum = gennum;21 }22 makeEnvelopeKnobs(elemPrefix: string, gennum: number, target: Model.TargetTag) {23 let pushControl = (c: IParameterControl) => {24 this.controls.push(c);25 };26 addKnob(GD(`${elemPrefix}_hold_time`),27 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_HT, Target: target}).then(pushControl);28 addKnob(GD(`${elemPrefix}_attack`),29 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_AR, Target: target}).then(pushControl);30 addKnob(GD(`${elemPrefix}_d1_r`),31 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_DR1, Target: target}).then(pushControl);32 addKnob(GD(`${elemPrefix}_d2_r`),33 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_DR2, Target: target}).then(pushControl);34 addKnob(GD(`${elemPrefix}_r1_r`),35 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_RR1, Target: target}).then(pushControl);36 addKnob(GD(`${elemPrefix}_r2_r`),37 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_RR2, Target: target}).then(pushControl);38 addKnob(GD(`${elemPrefix}_attack_level`),39 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_AL, Target: target}).then(pushControl);40 addKnob(GD(`${elemPrefix}_d1_l`),41 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_DL1, Target: target}).then(pushControl);42 addKnob(GD(`${elemPrefix}_s_l`),43 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_SL, Target: target}).then(pushControl);44 addKnob(GD(`${elemPrefix}_r1_l`),45 {Generator: gennum, Param: Model.ParamTag.TAG_ENV_RL1, Target: target}).then(pushControl);46 }47 node() {48 return this.element;49 }50}51/*52 struct Segment {53 Steinberg::Vst::RangeParameter *rate_param;54 Steinberg::Vst::RangeParameter *start_level_param;55 Steinberg::Vst::RangeParameter *end_level_param;56 VSTGUI::CCoord width;57 VSTGUI::CPoint start_point;58 VSTGUI::CPoint end_point;59 VSTGUI::CRect drag_box;60 };61 */62interface SegmentParams {63 rateParam: IRangeParameter | null;64 startLevelParam: IRangeParameter | null;65 endLevelParam: IRangeParameter | null;66}67type Point = [number, number];68type Rect = [number, number, number, number];69interface SegmentPoints {70 width: number;71 startPoint: Point;72 endPoint: Point;73 dragBox: Rect | null;74}75interface Segment {76 id: number;77 params: SegmentParams;78 points: SegmentPoints | null;79}80const kSustainDuration = 0.25;81const kDragboxWidthHeight = 8;82const kDragboxHalfWidthHeight = kDragboxWidthHeight / 2;83function EnvelopeRampCoefficient(start_level: number, end_level: number, length_in_samples: number) {84 return 1.0 + (Math.log(end_level) - Math.log(start_level)) / length_in_samples;85}86interface SegmentDecl {87 rateParam: Model.ParamTag | null;88 startLevelParam: Model.ParamTag | null;89 endLevelParam: Model.ParamTag | null;90}91const kSegmentDecls: { [id: number]: SegmentDecl } = {92 0: {rateParam: Model.ParamTag.TAG_ENV_HT, startLevelParam: null, endLevelParam: null},93 1: {rateParam: Model.ParamTag.TAG_ENV_AR, startLevelParam: null, endLevelParam: ParamTag.TAG_ENV_AL},94 2: {95 rateParam: Model.ParamTag.TAG_ENV_DR1,96 startLevelParam: ParamTag.TAG_ENV_AL,97 endLevelParam: ParamTag.TAG_ENV_DL198 },99 3: {100 rateParam: Model.ParamTag.TAG_ENV_DR2,101 startLevelParam: ParamTag.TAG_ENV_DL1,102 endLevelParam: ParamTag.TAG_ENV_SL103 },104 4: {rateParam: null, startLevelParam: Model.ParamTag.TAG_ENV_SL, endLevelParam: ParamTag.TAG_ENV_SL},105 5: {106 rateParam: Model.ParamTag.TAG_ENV_RR1,107 startLevelParam: ParamTag.TAG_ENV_SL,108 endLevelParam: ParamTag.TAG_ENV_RL1109 },110 6: {rateParam: Model.ParamTag.TAG_ENV_RR2, startLevelParam: ParamTag.TAG_ENV_RL1, endLevelParam: null},111}112type SegmentList = { [index: number]: Segment };113export class GraphicalEnvelopeEditorView implements GeneratorView, IDependent {114 private segments: SegmentList;115 private canvas: HTMLCanvasElement | null;116 private draggingSegment: Segment | null;117 constructor(readonly element: HTMLDivElement, private gennum: number, readonly target: Model.TargetTag) {118 const targetPrefix = Model.TargetTag[target].toString().toLowerCase();119 element.appendChild(MakeGraphicalEnvelopeEditor(targetPrefix));120 this.canvas = element.querySelector(`#${targetPrefix}-graph-env-canvas`);121 this.segments = {};122 this.draggingSegment = null;123 // // Subscribe for parameter changes for all envelope parameters.124 for (const param of [Model.ParamTag.TAG_ENV_HT, Model.ParamTag.TAG_ENV_AR, ParamTag.TAG_ENV_AL,125 Model.ParamTag.TAG_ENV_DR1, ParamTag.TAG_ENV_DL1,126 ParamTag.TAG_ENV_DR2,127 ParamTag.TAG_ENV_SL,128 ParamTag.TAG_ENV_RR1,129 ParamTag.TAG_ENV_RL1,130 ParamTag.TAG_ENV_RR2,]) {131 controller.subscribeParameter(Model.ParamIDFor({132 Generator: this.gennum,133 Param: param,134 Target: target135 }), this);136 }137 if (this.canvas) {138 this.canvas.addEventListener('mousedown', e => {139 this.onMouseDown(e);140 })141 this.canvas.addEventListener('mousemove', e => {142 this.onMouseMove(e);143 })144 this.canvas.addEventListener('mouseup', e => {145 this.onMouseUp(e);146 })147 }148 this.refresh();149 }150 refresh(ids: Array<number> | null = null) {151 this.updateSegments(ids).then((segments) => {152 this.redraw();153 });154 }155 loadSegmentParams(index: number,156 rateParam: Model.ParamTag | null,157 startLevelParam: Model.ParamTag | null,158 endLevelParam: Model.ParamTag | null): Promise<SegmentParams> {159 const promises = [160 rateParam != null ? controller.getParameterObject(Model.ParamIDFor({161 Generator: this.gennum,162 Param: rateParam,163 Target: this.target164 })) : null,165 startLevelParam != null ? controller.getParameterObject(Model.ParamIDFor({166 Generator: this.gennum,167 Param: startLevelParam,168 Target: this.target169 })) : null,170 endLevelParam != null ? controller.getParameterObject(Model.ParamIDFor({171 Generator: this.gennum,172 Param: endLevelParam,173 Target: this.target174 })) : null175 ]176 return new Promise((resolve, reject) => {177 const params = this.segments[index].params;178 Promise.all(promises).then((values) => {179 params.rateParam = <IRangeParameter>values[0];180 params.startLevelParam = <IRangeParameter>values[1];181 params.endLevelParam = <IRangeParameter>values[2];182 resolve(params);183 })184 })185 }186 emptySegment(id: number): Segment {187 return {188 id: id,189 params: {190 rateParam: null, endLevelParam: null, startLevelParam: null191 }, points: null192 };193 }194 updateSegments(updatedSegments: Array<number> | null = null): Promise<SegmentList> {195 if (!updatedSegments) updatedSegments = [0, 1, 2, 3, 4, 5, 6];196 let refreshPromises: Array<Promise<SegmentParams>> = [];197 for (const us of updatedSegments) {198 this.segments[us] = this.emptySegment(us);199 const sdecl = kSegmentDecls[us];200 refreshPromises.push(this.loadSegmentParams(201 us,202 sdecl.rateParam, sdecl.startLevelParam, sdecl.endLevelParam203 ))204 }205 // Once all segment params are loaded we can then proceed to do the calculations of points.206 return new Promise((resolve, reject) => {207 Promise.all(refreshPromises).then((segmentParams) => {208 let totalDuration = 0;209 for (const sd in this.segments) {210 if (!this.segments[sd] || !this.segments[sd].params) continue;211 const segmentParam = this.segments[sd].params;212 if (!segmentParam.rateParam) continue;213 if (Model.ParseTag(segmentParam.rateParam.info.id).Param == Model.ParamTag.TAG_ENV_SL) {214 totalDuration += kSustainDuration;215 } else {216 totalDuration += ValueOf(segmentParam.rateParam);217 }218 }219 if (this.canvas) {220 let xpos = 0;221 const height = this.canvas.height;222 const width = this.canvas.width;223 for (const s in this.segments) {224 const segment = this.segments[s];225 let duration = 0;226 if (segment.params.rateParam) {227 if (Model.ParseTag(segment.params.rateParam.info.id).Param == Model.ParamTag.TAG_ENV_SL) {228 duration = kSustainDuration;229 } else {230 duration = ValueOf(segment.params.rateParam);231 }232 }233 const start_level = ValueOf(segment.params.startLevelParam);234 const end_level = ValueOf(segment.params.endLevelParam);235 const yleft = height - (start_level * height);236 const yright = height - (end_level * height);237 const startPoint: Point = [xpos, yleft];238 const swidth = (duration / totalDuration) * width;239 xpos += swidth;240 const endPoint: Point = [xpos, yright];241 let dragBox: Rect | null = null;242 if (segment.params.rateParam || segment.params.startLevelParam) {243 dragBox = [244 endPoint[0] - kDragboxHalfWidthHeight,245 endPoint[1] - kDragboxHalfWidthHeight,246 kDragboxWidthHeight, kDragboxWidthHeight247 ]248 }249 segment.points = {250 width: swidth,251 startPoint: startPoint,252 endPoint: endPoint,253 dragBox: dragBox254 }255 }256 }257 resolve(this.segments);258 });259 });260 }261 onMouseDown(event: MouseEvent) {262 if (!this.draggingSegment) {263 for (const sid in this.segments) {264 const s = this.segments[sid];265 if (!s.points) continue;266 if (!s.points.dragBox) continue;267 if (event.offsetX >= s.points.dragBox[0] &&268 event.offsetY >= s.points.dragBox[1] &&269 event.offsetX <= s.points.dragBox[0] + s.points.dragBox[2] &&270 event.offsetY <= s.points.dragBox[1] + s.points.dragBox[3]) {271 this.draggingSegment = s;272 }273 }274 }275 }276 onMouseMove(event: MouseEvent) {277 if (!this.draggingSegment) return;278 if (!this.canvas) return;279 if (!this.draggingSegment.params || !this.draggingSegment.points || !this.draggingSegment.points.width) return;280 if (event.offsetX < 0 && event.offsetY < 0) return;281 if (event.offsetX > this.canvas.width || event.offsetY > this.canvas.height) return;282 if (!this.draggingSegment.points.dragBox) return;283 let changed = false;284 const deltaX = event.offsetX - this.draggingSegment.points.dragBox[0] + kDragboxHalfWidthHeight;285 const rateParam = this.draggingSegment.params.rateParam;286 if (rateParam && deltaX) {287 const deltaR = deltaX / this.draggingSegment.points.width;288 const newValue = Math.max(rateParam.normalized + deltaR, 0.0001);289 controller.setParamNormalized(rateParam.info.id, newValue);290 changed = true;291 }292 const levelParam = this.draggingSegment.params.endLevelParam;293 if (levelParam) {294 // float change_n = 1 - (y / getHeight());295 const deltaL = 1 - (event.offsetY / this.canvas.height);296 controller.setParamNormalized(levelParam.info.id, deltaL);297 changed = true;298 }299 }300 onMouseUp(event: MouseEvent) {301 this.draggingSegment = null;302 }303 node(): HTMLElement {304 return this.element;305 }306 changed(parameter: IParameter): void {307 let tag = ParseTag(parameter.info.id);308 if (tag.Generator == this.gennum && tag.Target == this.target) {309 let updatedSegments: Array<number> = [];310 for (const sd in this.segments) {311 const segment = this.segments[sd];312 if (!segment.params) continue;313 if (segment.params.rateParam?.info.id == parameter.info.id ||314 segment.params.endLevelParam?.info.id == parameter.info.id ||315 segment.params.startLevelParam?.info.id == parameter.info.id)316 updatedSegments.push(segment.id);317 }318 this.refresh(updatedSegments);319 }320 }321 updateSelectedGenerator(gennum: number): void {322 this.gennum = gennum;323 this.refresh();324 }325 redraw() {326 if (!this.segments || !this.canvas) return;327 let ctx = this.canvas.getContext("2d");328 if (!ctx) return;329 ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);330 ctx.beginPath();331 ctx.lineWidth = 3;332 ctx.strokeStyle = "#1e2a96";333 ctx.moveTo(0, this.canvas.height);334 let x = 0;335 for (const sid in this.segments) {336 const s = this.segments[sid];337 if (!s.points) continue;338 let level = ValueOf(s.params.startLevelParam);339 if (level == 0) level = 0.001;340 let end_level = ValueOf(s.params.endLevelParam);341 if (end_level == 0) end_level = 0.001;342 const co = EnvelopeRampCoefficient(level, end_level, s.points.width);343 for (let i = 0; i < s.points.width; i++) {344 level *= co;345 let height = level * this.canvas.height;346 ctx.lineTo(x++, this.canvas.height - height);347 }348 }349 ctx.stroke();350 ctx.lineWidth = 1;351 ctx.beginPath();352 for (const sid in this.segments) {353 const s = this.segments[sid];354 if ((s.params.rateParam || s.params.endLevelParam) && s.points?.dragBox) {355 ctx.rect(s.points.dragBox[0], s.points.dragBox[1], s.points.dragBox[2], s.points.dragBox[3]);356 }357 }358 ctx.stroke();359 }...

Full Screen

Full Screen

log.ts

Source:log.ts Github

copy

Full Screen

1import path from 'path';2import util from 'util';3import { utils } from './utils';4import { datetimeUtils } from './datetimeUtils';56const workdir = process.cwd();7/**8 * 取文件名的短名称9 * 用于缩短日志文件名前缀的函数10 * @param paramFileName 文件名11 * @return 去除当前路径的文件短名12 */13function shortpath(paramFileName: string): string {14 let ff = paramFileName.replace(workdir, '');15 const ext = path.extname(ff);16 let pp = path.dirname(ff);17 const basename = path.basename(ff, ext);1819 let spltchar = '/';20 if (pp.indexOf('\\') >= 0) {21 spltchar = '\\';22 }2324 if (pp === '\\' || pp === '/' || pp === '.') {25 pp = '';26 }2728 if (pp.length > 0) {29 ff = path.dirname(ff) + spltchar + basename;30 } else {31 ff = basename;32 }3334 const sss = ff.charAt(0);35 if (sss === '\\' || sss === '/') {36 ff = ff.slice(1);37 }3839 return `${ff}`;40}41/**42 * 生成日志前缀43 * @param paramFilename 当前的文件名44 * @param args 其它前缀45 * @return 返回结果46 */47export function logPrefix(paramFilename: string, ...args: unknown[]): unknown[] {48 if (paramFilename === null || paramFilename === undefined) {49 return [...args];50 } else {51 return [shortpath(paramFilename), ...args];52 }53}5455export interface ILog {56 name: string;57 trace(...paramLog: unknown[]): void;58 debug(...paramLog: unknown[]): void;59 /** log级别日志,等同于info */60 log(...paramLog: unknown[]): void;61 info(...paramLog: unknown[]): void;62 error(...paramLog: unknown[]): void;63 warn(...paramLog: unknown[]): void;64 msg(...paramLog: unknown[]): void;65}6667/**68 * 控制台日志类69 */70export class LogConsole implements ILog {71 private m_name: string = '';72 /**73 * 控制台日志构造函数74 * @param {string} [paramName=''] tag名称75 */76 public constructor(paramName = '') {77 this.m_name = paramName;78 }7980 public get name() {81 return this.m_name;82 }8384 public set name(paramName) {85 this.m_name = paramName;86 }8788 private buildLog(categoryName: string, level: string, ...data: unknown[]) {89 return `[${categoryName} ${datetimeUtils.nowDateString()} ${level}] ${util.format('', ...data)}`;90 }9192 public trace(...paramLog: unknown[]): void {93 // tslint:disable-next-line: no-console94 console.log(this.buildLog(this.name, 'TRACE', ...paramLog));95 }96 public debug(...paramLog: unknown[]) {97 // tslint:disable-next-line: no-console98 console.log(this.buildLog(this.name, 'DEBUG', ...paramLog));99 }100 public log(...paramLog: unknown[]) {101 // tslint:disable-next-line: no-console102 console.log(this.buildLog(this.name, ' LOG', ...paramLog));103 }104 public info(...paramLog: unknown[]) {105 // tslint:disable-next-line: no-console106 console.log(this.buildLog(this.name, ' INFO', ...paramLog));107 }108 public warn(...paramLog: unknown[]) {109 // tslint:disable-next-line: no-console110 console.log(this.buildLog(this.name, ' WARN', ...paramLog));111 }112 public error(...paramLog: unknown[]) {113 // tslint:disable-next-line: no-console114 console.log(this.buildLog(this.name, 'ERROR', ...paramLog));115 }116 public fatal(...paramLog: unknown[]) {117 // tslint:disable-next-line: no-console118 console.log(this.buildLog(this.name, 'FATEL', ...paramLog));119 }120 public msg(...paramLog: unknown[]) {121 // tslint:disable-next-line: no-console122 console.log(this.buildLog(this.name, ' MSG', ...paramLog));123 }124}125126let defaultLog: ILog = new LogConsole('default');127128/**129 * 日志管理器130 *131 * @class LogManager132 */133class LogManager {134 private m_MapLogger = new Map<string, ILog>();135 private m_createLog: (paramTag: string) => ILog = (paramTag: string) => new LogConsole(paramTag);136137 /**138 * 取指定tag的日志139 * @param paramTag 指定的tag140 */141 public getLogger(paramTag: string): ILog {142 if (utils.isString(paramTag) && paramTag.length > 0) {143 let l = this.m_MapLogger.get(paramTag);144145 if (utils.isNull(l)) {146 l = this.m_createLog(paramTag);147 this.m_MapLogger.set(paramTag, l);148 }149 return l as ILog;150 } else {151 return defaultLog;152 }153 }154 /** 设置缺省的log */155 public setDefaultLog(paramDefaultLog: ILog) {156 defaultLog = paramDefaultLog;157 }158 /** 设置创建log */159 public setCreateLog(paramCreateLog: (paramTag: string) => ILog) {160 this.m_createLog = paramCreateLog;161 }162}163164/**165 * 日志管理器166 */167const logManager = new LogManager();168/**169 * @deprecated 不建议使用,可以直接使用logManager的setCreateLog方法,设置创建函数170 */171export type TGetLoggerFun = (paramTag: string) => ILog;172/**173 * 取日志管理实例174 * @returns175 */176export function GetLogManager() {177 return logManager;178}179/**180 * 取指定tag的log181 * 如果没有这个tag的日志,则创建一个182 * @param paramTag 取指定tag的log183 * @return 返回log184 */185let __getLogger: TGetLoggerFun = (paramTag: string): ILog => {186 const [prefix] = logPrefix(paramTag);187 return logManager.getLogger(prefix as string);188};189/**190 * 取指定tag的local log191 * 如果没有这个tag的日志,则创建一个192 * @param paramTag 取指定tag的log193 * @return 返回log194 */195export function getLocalLogger(paramTag: string): ILog {196 return logManager.getLogger(paramTag);197}198199/**200 * 重新设置getLogger201 * - 返回true表示设置成功202 * - 返回false表示paramGetLogger不是一个函数203 * @deprecated 不建议使用,可以直接使用logManager的setCreateLog方法,设置创建函数204 * @param {function} paramGetLogger 新的getLogger函数实现,替换getLogger205 * @return {boolean} 设置结果206 */207export function setGetLogger(paramGetLogger: (paramTag: string) => ILog) {208 if (utils.isFunction(paramGetLogger)) {209 __getLogger = paramGetLogger;210 return true;211 }212 return false;213}214215export function getLogger(paramTag: string): ILog {216 return __getLogger(paramTag); ...

Full Screen

Full Screen

log.js

Source:log.js Github

copy

Full Screen

1"use strict";2var __importDefault = (this && this.__importDefault) || function (mod) {3 return (mod && mod.__esModule) ? mod : { "default": mod };4};5Object.defineProperty(exports, "__esModule", { value: true });6exports.getLogger = exports.setGetLogger = exports.getLocalLogger = exports.GetLogManager = exports.LogConsole = exports.logPrefix = void 0;7const path_1 = __importDefault(require("path"));8const util_1 = __importDefault(require("util"));9const utils_1 = require("./utils");10const datetimeUtils_1 = require("./datetimeUtils");11const workdir = process.cwd();12/**13 * 取文件名的短名称14 * 用于缩短日志文件名前缀的函数15 * @param paramFileName 文件名16 * @return 去除当前路径的文件短名17 */18function shortpath(paramFileName) {19 let ff = paramFileName.replace(workdir, '');20 const ext = path_1.default.extname(ff);21 let pp = path_1.default.dirname(ff);22 const basename = path_1.default.basename(ff, ext);23 let spltchar = '/';24 if (pp.indexOf('\\') >= 0) {25 spltchar = '\\';26 }27 if (pp === '\\' || pp === '/' || pp === '.') {28 pp = '';29 }30 if (pp.length > 0) {31 ff = path_1.default.dirname(ff) + spltchar + basename;32 }33 else {34 ff = basename;35 }36 const sss = ff.charAt(0);37 if (sss === '\\' || sss === '/') {38 ff = ff.slice(1);39 }40 return `${ff}`;41}42/**43 * 生成日志前缀44 * @param paramFilename 当前的文件名45 * @param args 其它前缀46 * @return 返回结果47 */48function logPrefix(paramFilename, ...args) {49 if (paramFilename === null || paramFilename === undefined) {50 return [...args];51 }52 else {53 return [shortpath(paramFilename), ...args];54 }55}56exports.logPrefix = logPrefix;57/**58 * 控制台日志类59 */60class LogConsole {61 /**62 * 控制台日志构造函数63 * @param {string} [paramName=''] tag名称64 */65 constructor(paramName = '') {66 this.m_name = '';67 this.m_name = paramName;68 }69 get name() {70 return this.m_name;71 }72 set name(paramName) {73 this.m_name = paramName;74 }75 buildLog(categoryName, level, ...data) {76 return `[${categoryName} ${datetimeUtils_1.datetimeUtils.nowDateString()} ${level}] ${util_1.default.format('', ...data)}`;77 }78 trace(...paramLog) {79 // tslint:disable-next-line: no-console80 console.log(this.buildLog(this.name, 'TRACE', ...paramLog));81 }82 debug(...paramLog) {83 // tslint:disable-next-line: no-console84 console.log(this.buildLog(this.name, 'DEBUG', ...paramLog));85 }86 log(...paramLog) {87 // tslint:disable-next-line: no-console88 console.log(this.buildLog(this.name, ' LOG', ...paramLog));89 }90 info(...paramLog) {91 // tslint:disable-next-line: no-console92 console.log(this.buildLog(this.name, ' INFO', ...paramLog));93 }94 warn(...paramLog) {95 // tslint:disable-next-line: no-console96 console.log(this.buildLog(this.name, ' WARN', ...paramLog));97 }98 error(...paramLog) {99 // tslint:disable-next-line: no-console100 console.log(this.buildLog(this.name, 'ERROR', ...paramLog));101 }102 fatal(...paramLog) {103 // tslint:disable-next-line: no-console104 console.log(this.buildLog(this.name, 'FATEL', ...paramLog));105 }106 msg(...paramLog) {107 // tslint:disable-next-line: no-console108 console.log(this.buildLog(this.name, ' MSG', ...paramLog));109 }110}111exports.LogConsole = LogConsole;112let defaultLog = new LogConsole('default');113/**114 * 日志管理器115 *116 * @class LogManager117 */118class LogManager {119 constructor() {120 this.m_MapLogger = new Map();121 this.m_createLog = (paramTag) => new LogConsole(paramTag);122 }123 /**124 * 取指定tag的日志125 * @param paramTag 指定的tag126 */127 getLogger(paramTag) {128 if (utils_1.utils.isString(paramTag) && paramTag.length > 0) {129 let l = this.m_MapLogger.get(paramTag);130 if (utils_1.utils.isNull(l)) {131 l = this.m_createLog(paramTag);132 this.m_MapLogger.set(paramTag, l);133 }134 return l;135 }136 else {137 return defaultLog;138 }139 }140 /** 设置缺省的log */141 setDefaultLog(paramDefaultLog) {142 defaultLog = paramDefaultLog;143 }144 /** 设置创建log */145 setCreateLog(paramCreateLog) {146 this.m_createLog = paramCreateLog;147 }148}149/**150 * 日志管理器151 */152const logManager = new LogManager();153/**154 * 取日志管理实例155 * @returns156 */157function GetLogManager() {158 return logManager;159}160exports.GetLogManager = GetLogManager;161/**162 * 取指定tag的log163 * 如果没有这个tag的日志,则创建一个164 * @param paramTag 取指定tag的log165 * @return 返回log166 */167let __getLogger = (paramTag) => {168 const [prefix] = logPrefix(paramTag);169 return logManager.getLogger(prefix);170};171/**172 * 取指定tag的local log173 * 如果没有这个tag的日志,则创建一个174 * @param paramTag 取指定tag的log175 * @return 返回log176 */177function getLocalLogger(paramTag) {178 return logManager.getLogger(paramTag);179}180exports.getLocalLogger = getLocalLogger;181/**182 * 重新设置getLogger183 * - 返回true表示设置成功184 * - 返回false表示paramGetLogger不是一个函数185 * @deprecated 不建议使用,可以直接使用logManager的setCreateLog方法,设置创建函数186 * @param {function} paramGetLogger 新的getLogger函数实现,替换getLogger187 * @return {boolean} 设置结果188 */189function setGetLogger(paramGetLogger) {190 if (utils_1.utils.isFunction(paramGetLogger)) {191 __getLogger = paramGetLogger;192 return true;193 }194 return false;195}196exports.setGetLogger = setGetLogger;197function getLogger(paramTag) {198 return __getLogger(paramTag);199} ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 parameters: {3 paramTag: {4 }5 }6}7import React from 'react'8import { storiesOf } from '@storybook/react'9import Test from './test'10storiesOf('Test', module)11 .add('test', () => <Test/>)12import React from 'react'13import { storiesOf } from '@storybook/react'14import Test from './test'15storiesOf('Test', module)16 .add('test', () => <Test/>)17 .addParameters({18 paramTag: {19 }20 })21import React from 'react'22import { storiesOf } from '@storybook/react'23import Test from './test'24storiesOf('Test', module)25 .add('test', () => <Test/>, {26 paramTag: {27 }28 })29import React from 'react'30import { storiesOf } from '@storybook/react'31import Test from './test'32storiesOf('Test', module)33 .add('test', () => <Test/>, {34 paramTag: {35 }36 })37 .addParameters({38 paramTag: {39 }40 })41import React from 'react'42import { storiesOf } from '@storybook/react'43import Test from './test'44storiesOf('Test', module)45 .add('test', () => <Test/>, {46 paramTag: {47 }48 })49 .add('test2', () => <Test/>, {50 paramTag: {51 }52 })53import React from 'react'54import { storiesOf } from '@storybook/react'55import Test from './test'56storiesOf('Test', module)57 .add('test', () => <Test/>, {58 paramTag: {59 }60 })61 .add('test2', () => <Test/>, {62 paramTag: {63 }64 })65 .addParameters({66 paramTag: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const paramTag = require('storybook-root').paramTag;2const test = paramTag('test');3console.log(test);4const paramTag = require('storybook-root').paramTag;5const test2 = paramTag('test2');6console.log(test2);7const paramTag = require('storybook-root').paramTag;8const test3 = paramTag('test3');9console.log(test3);10const paramTag = require('storybook-root').paramTag;11const test4 = paramTag('test4');12console.log(test4);13const paramTag = require('storybook-root').paramTag;14const test5 = paramTag('test5');15console.log(test5);16const paramTag = require('storybook-root').paramTag;17const test6 = paramTag('test6');18console.log(test6);19const paramTag = require('storybook-root').paramTag;20const test7 = paramTag('test7');21console.log(test7);22const paramTag = require('storybook-root').paramTag;23const test8 = paramTag('test8');24console.log(test8);25const paramTag = require('storybook-root').paramTag;26const test9 = paramTag('test9');27console.log(test9);28const paramTag = require('storybook-root').paramTag;29const test10 = paramTag('test10');30console.log(test10

Full Screen

Using AI Code Generation

copy

Full Screen

1const paramTag = require('storybook-root').paramTag;2const test = paramTag('test');3console.log(test);4const paramTag = (tag) => {5 return tag;6}7module.exports = {8}9I have a question. Why do you need to use require('storybook-root') if you can use require('./storybook-root') ?

Full Screen

Using AI Code Generation

copy

Full Screen

1import { paramTag } from 'storybook-root';2const story = paramTag('story');3const story2 = paramTag('story2');4import { storybookRoot } from 'storybook-root';5storybookRoot({6 {7 component: () => <div>story</div>,8 },9 {10 component: () => <div>story2</div>,11 },12});13import { storybookRoot } from 'storybook-root';14storybookRoot({15 {16 component: () => <div>story</div>,17 },18 {19 component: () => <div>story2</div>,20 },21 config: {22 },23});24import { storybookRoot } from 'storybook-root';25storybookRoot({26 {27 component: () => <div>story</div>,28 },29 {30 component: () => <div>story2</div>,31 },32 config: {33 },34 decorator: () => {35 return <div>Decorator</div>;36 },37});38import { storybookRoot } from 'storybook-root';39storybookRoot({40 {41 component: () => <div>story</div>,42 },43 {44 component: () => <div>story2</div>,45 },46 config: {47 },48 decorator: () => {49 return <div>Decorator</div>;50 },51});52import { storybookRoot } from 'storybook-root';53storybookRoot({54 {55 component: () => <div>story</div>,56 },57 {58 component: () => <div>story2</div>,59 },

Full Screen

Using AI Code Generation

copy

Full Screen

1let root = require('storybook-root');2let paramTag = root.paramTag;3let param = paramTag('paramName');4console.log(param);5{6}7let root = require('storybook-root');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { paramTag } from 'storybook-root'2import MyComponent from './MyComponent'3export default {4}5export const withId = paramTag('id')(MyComponent)6import { withId } from './test'7export default {8 parameters: {9 }10}11import React from 'react'12const MyComponent = ({ id }) => {13 return <div id={id} />14}15import { render } from '@testing-library/react'16import MyComponent from './MyComponent'17describe('MyComponent', () => {18 it('renders the id prop', () => {19 const { getByText } = render(<MyComponent id="someId" />)20 expect(getByText('someId')).toBeInTheDocument()21 })22})

Full Screen

Using AI Code Generation

copy

Full Screen

1import { paramTag } from 'storybook-root';2paramTag('story-name', 'storybook-name').then(element => {3});4import { paramTag } from 'storybook-root';5paramTag('story-name', 'storybook-name').then(element => {6});7import { paramTag } from 'storybook-root';8paramTag('story-name', 'storybook-name').then(element => {9});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful