How to use _storyStore method in storybook-root

Best JavaScript code snippet using storybook-root

client_api.ts

Source:client_api.ts Github

copy

Full Screen

1/* eslint no-underscore-dangle: 0 */2import { logger } from '@storybook/client-logger';3import { StoryFn, Parameters, DecorateStoryFunction } from '@storybook/addons';4import { toId } from '@storybook/csf';5import { ClientApiParams, DecoratorFunction, ClientApiAddons, StoryApi } from './types';6import { applyHooks } from './hooks';7import StoryStore from './story_store';8import { defaultDecorateStory } from './decorators';9// ClientApi (and StoreStore) are really singletons. However they are not created until the10// relevant framework instanciates them via `start.js`. The good news is this happens right away.11let singleton: ClientApi;12export const addDecorator = (decorator: DecoratorFunction) => {13 if (!singleton)14 throw new Error(`Singleton client API not yet initialized, cannot call addDecorator`);15 singleton.addDecorator(decorator);16};17export const addParameters = (parameters: Parameters) => {18 if (!singleton)19 throw new Error(`Singleton client API not yet initialized, cannot call addParameters`);20 singleton.addParameters(parameters);21};22export default class ClientApi {23 private _storyStore: StoryStore;24 private _addons: ClientApiAddons<unknown>;25 private _decorateStory: DecorateStoryFunction;26 // React Native Fast refresh doesn't allow multiple dispose calls27 private _noStoryModuleAddMethodHotDispose: boolean;28 constructor({29 storyStore,30 decorateStory = defaultDecorateStory,31 noStoryModuleAddMethodHotDispose,32 }: ClientApiParams) {33 this._storyStore = storyStore;34 this._addons = {};35 this._noStoryModuleAddMethodHotDispose = noStoryModuleAddMethodHotDispose || false;36 this._decorateStory = decorateStory;37 if (!storyStore) throw new Error('storyStore is required');38 singleton = this;39 }40 setAddon = (addon: any) => {41 this._addons = {42 ...this._addons,43 ...addon,44 };45 };46 getSeparators = () => {47 const { hierarchySeparator, hierarchyRootSeparator, showRoots } =48 this._storyStore._globalMetadata.parameters.options || {};49 // Note these checks will be removed in 6.0, leaving this much simpler50 if (51 typeof hierarchySeparator !== 'undefined' ||52 typeof hierarchyRootSeparator !== 'undefined'53 ) {54 return { hierarchySeparator, hierarchyRootSeparator };55 }56 if (57 typeof showRoots === 'undefined' &&58 this.store()59 .getStoryKinds()60 .some(kind => kind.match(/\.|\|/))61 ) {62 return {63 hierarchyRootSeparator: '|',64 hierarchySeparator: /\/|\./,65 };66 }67 return { hierarchySeparator: '/' };68 };69 addDecorator = (decorator: DecoratorFunction) => {70 this._storyStore.addGlobalMetadata({ decorators: [decorator], parameters: {} });71 };72 addParameters = (parameters: Parameters) => {73 this._storyStore.addGlobalMetadata({ decorators: [], parameters });74 };75 clearDecorators = () => {76 this._storyStore.clearGlobalDecorators();77 };78 // what are the occasions that "m" is a boolean vs an obj79 storiesOf = <StoryFnReturnType = unknown>(80 kind: string,81 m: NodeModule82 ): StoryApi<StoryFnReturnType> => {83 if (!kind && typeof kind !== 'string') {84 throw new Error('Invalid or missing kind provided for stories, should be a string');85 }86 if (!m) {87 logger.warn(88 `Missing 'module' parameter for story with a kind of '${kind}'. It will break your HMR`89 );90 }91 if (m) {92 const proto = Object.getPrototypeOf(m);93 if (proto.exports && proto.exports.default) {94 // FIXME: throw an error in SB6.095 logger.error(96 `Illegal mix of CSF default export and storiesOf calls in a single file: ${proto.i}`97 );98 }99 }100 if (m && m.hot && m.hot.dispose) {101 m.hot.dispose(() => {102 const { _storyStore } = this;103 // If HMR dispose happens in a story file, we know that HMR will pass up to the configuration file (preview.js)104 // and be handled by the HMR.allow in config_api, leading to a re-run of configuration.105 // So configuration is about to happen--we can skip the safety check.106 _storyStore.removeStoryKind(kind, { allowUnsafe: true });107 _storyStore.incrementRevision();108 });109 }110 let hasAdded = false;111 const api: StoryApi<StoryFnReturnType> = {112 kind: kind.toString(),113 add: () => api,114 addDecorator: () => api,115 addParameters: () => api,116 };117 // apply addons118 Object.keys(this._addons).forEach(name => {119 const addon = this._addons[name];120 api[name] = (...args: any[]) => {121 addon.apply(api, args);122 return api;123 };124 });125 api.add = (126 storyName: string,127 storyFn: StoryFn<StoryFnReturnType>,128 parameters: Parameters = {}129 ) => {130 hasAdded = true;131 const id = parameters.__id || toId(kind, storyName);132 if (typeof storyName !== 'string') {133 throw new Error(`Invalid or missing storyName provided for a "${kind}" story.`);134 }135 if (!this._noStoryModuleAddMethodHotDispose && m && m.hot && m.hot.dispose) {136 m.hot.dispose(() => {137 const { _storyStore } = this;138 // See note about allowUnsafe above139 _storyStore.remove(id, { allowUnsafe: true });140 _storyStore.incrementRevision();141 });142 }143 const fileName = m && m.id ? `${m.id}` : undefined;144 const { decorators, ...storyParameters } = parameters;145 this._storyStore.addStory(146 {147 id,148 kind,149 name: storyName,150 storyFn,151 parameters: { fileName, ...storyParameters },152 decorators,153 },154 {155 applyDecorators: applyHooks(this._decorateStory),156 }157 );158 return api;159 };160 api.addDecorator = (decorator: DecoratorFunction<StoryFnReturnType>) => {161 if (hasAdded)162 throw new Error(`You cannot add a decorator after the first story for a kind.163Read more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decorators-parameters-after-stories`);164 this._storyStore.addKindMetadata(kind, { decorators: [decorator], parameters: [] });165 return api;166 };167 api.addParameters = (parameters: Parameters) => {168 if (hasAdded)169 throw new Error(`You cannot add parameters after the first story for a kind.170Read more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decorators-parameters-after-stories`);171 this._storyStore.addKindMetadata(kind, { decorators: [], parameters });172 return api;173 };174 return api;175 };176 getStorybook = () => this._storyStore.getStorybook();177 raw = () => this._storyStore.raw();178 // FIXME: temporary expose the store for react-native179 // Longer term react-native should use the Provider/Consumer api180 store = () => this._storyStore;...

Full Screen

Full Screen

config_api.ts

Source:config_api.ts Github

copy

Full Screen

1/* eslint no-underscore-dangle: 0 */2import StoryStore from './story_store';3export default class ConfigApi {4 _storyStore: StoryStore;5 constructor({ storyStore }: { storyStore: StoryStore }) {6 this._storyStore = storyStore;7 }8 configure = (loaders: () => void, module: NodeModule, showDeprecationWarning = true) => {9 this._storyStore.startConfiguring();10 try {11 loaders();12 this._storyStore.clearError();13 } catch (err) {14 this._storyStore.setError(err);15 }16 this._storyStore.finishConfiguring();17 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1export const getStorybookRootAttribute = () => {2 const root = document.querySelector('[storybook-root-attribute]');3 const storyStore = root._storyStore;4 return storyStore;5};6export const getStorybookRootAttribute = () => {7 const root = document.querySelector('[storybook-root-attribute]');8 const storyStore = root._storyStore;9 return storyStore;10};11export const getStorybookRootAttribute = () => {12 const root = document.querySelector('[storybook-root-attribute]');13 const storyStore = root._storyStore;14 return storyStore;15};16export const getStorybookRootAttribute = () => {17 const root = document.querySelector('[storybook-root-attribute]');18 const storyStore = root._storyStore;19 return storyStore;20};21export const getStorybookRootAttribute = () => {22 const root = document.querySelector('[storybook-root-attribute]');23 const storyStore = root._storyStore;24 return storyStore;25};26export const getStorybookRootAttribute = () => {27 const root = document.querySelector('[storybook-root-attribute]');28 const storyStore = root._storyStore;29 return storyStore;30};31export const getStorybookRootAttribute = () => {32 const root = document.querySelector('[storybook-root-attribute]');33 const storyStore = root._storyStore;34 return storyStore;35};36export const getStorybookRootAttribute = () => {37 const root = document.querySelector('[storybook-root-attribute]');38 const storyStore = root._storyStore;39 return storyStore;40};41export const getStorybookRootAttribute = () => {42 const root = document.querySelector('[storybook-root-attribute]');43 const storyStore = root._storyStore;44 return storyStore;45};

Full Screen

Using AI Code Generation

copy

Full Screen

1const storyStore = window._storyStore;2const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;3const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;4const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;5const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;6const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;7const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;8const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;9const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;10const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;11const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;12const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;13const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;14const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;15const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;16const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;17const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;18const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;19const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;20const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;21const storyStore = window.__STORYBOOK_CLIENT_API__.storyStore;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { _storyStore } = require("@storybook/root-logger");2const { getStoryId, getStoryName } = require("@storybook/csf");3const storyId = getStoryId("Button", "Primary");4const storyName = getStoryName("Button", "Primary");5const loggers = _storyStore.getStoryContext(storyId).loggers;6loggers.info("Info message");7loggers.warn("Warn message");8loggers.error("Error message");9loggers.debug("Debug message");10loggers.trace("Trace message");11loggers.infoRoot("Info message");12loggers.warnRoot("Warn message");13loggers.errorRoot("Error message");14loggers.debugRoot("Debug message");15loggers.traceRoot("Trace message");16loggers.infoBoth("Info message");17loggers.warnBoth("Warn message");18loggers.errorBoth("Error message");19loggers.debugBoth("Debug message");20loggers.traceBoth("Trace message");21loggers.infoBothStoryName("Info message");22loggers.warnBothStoryName("Warn message");23loggers.errorBothStoryName("Error message");24loggers.debugBothStoryName("Debug message");25loggers.traceBothStoryName("Trace message");26loggers.infoBothStoryNameAndId("Info message");27loggers.warnBothStoryNameAndId("Warn message");28loggers.errorBothStoryNameAndId("Error message");29loggers.debugBothStoryNameAndId("Debug message");30loggers.traceBothStoryNameAndId("Trace message");31loggers.infoBothStoryId("Info message");32loggers.warnBothStoryId("Warn

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