Best JavaScript code snippet using storybook-root
Inheritable.js
Source:Inheritable.js
...47 *48 * If these values change dynamically, these properties must be maintained. For example:49 *50 * updateHidden: function (hidden) {51 * var inherited = this.getInherited();52 *53 * if (hidden) {54 * inherited.hidden = true;55 * } else {56 * // Unmask whatever may be inherited:57 * delete inherited.hidden;58 * }59 * }60 *61 * ## Proper Usage62 *63 * ALWAYS access inherited state using `getInherited` or `getInheritedConfig`, not by64 * accessing `inheritedState` directly.65 *66 * The `inheritedState` property does not exist until the first call to `getInherited`. At67 * that point `getInherited` walks up the component tree to establish the `inheritedState`68 * prototype chain. Additionally the `inheritedState` property should NOT be relied upon69 * even after the initial call to `getInherited` because it is possible for it to become70 * invalid.71 *72 * Invalidation typically happens when a component is moved to a new container. In such a73 * case the `inheritedState` remains invalid until the next time `getInherited` is called74 * on the component or one of its descendants.75 * @private76 * @since 5.0.077 */78Ext.define('Ext.mixin.Inheritable', {79 extend: 'Ext.Mixin',80 mixinConfig: {81 id: 'inheritable'82 },83 /**84 * This method returns an object containing the inherited properties for this instance.85 *86 * @param {Boolean} [inner=false] Pass `true` to return `inheritedStateInner` instead87 * of the normal `inheritedState` object. This is only needed internally and should88 * not be passed by user code.89 *90 * @return {Object} The `inheritedState` object containing inherited properties.91 * @since 5.0.092 */93 getInherited: function (inner) {94 var me = this,95 inheritedState = (inner && me.inheritedStateInner) || me.inheritedState,96 ownerCt = me.ownerCt || me.initOwnerCt,97 isContainer = me.isContainer,98 parent, inheritedStateInner, getInner;99 if (!inheritedState || inheritedState.invalid) {100 // Use upward navigational link, not ownerCt.101 // 99% of the time, this will use ownerCt/floatParent.102 // Certain floating components do not have an ownerCt, but they are still linked103 // into a navigational hierarchy. The getRefOwner method normalizes these differences.104 parent = me.getRefOwner();105 if (ownerCt) {106 // This will only be true if the item is a "child" of its owning container107 // For example, a docked item will not get the inner inheritedState.108 getInner = me.ownerLayout === ownerCt.layout;109 }110 me.inheritedState = inheritedState =111 // chain this component's inheritedState to that of its parent. If it112 // doesn't have a parent, then chain to the rootInheritedState. This is113 // done so that when there is a viewport, all component's will inherit114 // from its inheritedState, even components that are not descendants of115 // the viewport.116 Ext.Object.chain(parent ? parent.getInherited(getInner)117 : Ext.rootInheritedState);118 if (isContainer) {119 me.inheritedStateInner = inheritedStateInner = Ext.Object.chain(inheritedState);120 }121 me.initInheritedState(inheritedState, inheritedStateInner);122 // initInheritedState is allowed to replace the objects we provide, so we go123 // back to the instance here at the end.124 inheritedState = (isContainer && inner) ? me.inheritedStateInner : me.inheritedState;125 }126 return inheritedState;127 },128 /**129 * This method returns the value of a config property that may be inherited from some130 * ancestor.131 *132 * In some cases, a config may be explicitly set on a component with the intent of133 * *only* being presented to its children while that component should act upon the134 * inherited value (see `referenceHolder` for example). In these cases the `skipThis`135 * parameter should be specified as `true`.136 *137 * @param {String} property The name of the config property to return.138 * @param {Boolean} [skipThis=false] Pass `true` if the property should be ignored if139 * found on this instance. In other words, `true` means the property must be inherited140 * and not explicitly set on this instance.141 * @return {Mixed} The value of the requested `property`.142 * @since 5.0.0143 */144 getInheritedConfig: function (property, skipThis) {145 var state = this.inheritedState,146 old, ret;147 // Avoid the extra method call since user has already made one to get here148 if (!state || state.invalid) {149 state = this.getInherited();150 }151 ret = state[property];152 if (skipThis && state.hasOwnProperty(property)) {153 old = ret;154 delete state[property];155 ret = state[property];156 state[property] = old;157 }158 return ret;159 },160 /**161 * Sets up a reference on our current reference holder.162 *163 * @private164 */165 fixReference: function() {166 var me = this,167 refHolder;168 if (me.reference) {169 refHolder = me.lookupReferenceHolder();170 if (refHolder) {171 refHolder.attachReference(me);172 }173 }174 },175 /**176 * Gets the Controller or Component that is used as the event root for this view.177 *178 * @param {Object} [defaultScope=this] The default scope to return if none is found.179 * @return {Ext.app.ViewController/Ext.container.Container} The default listener scope.180 *181 * @protected182 * @since 5.0.0183 */184 resolveListenerScope: function (defaultScope, /* private */ skipThis) {185 var me = this,186 hasSkipThis = (typeof skipThis === 'boolean'),187 namedScope = Ext._namedScopes[defaultScope],188 ret;189 if (!namedScope) {190 // If there is no named scope we know for sure that the listener was not191 // declared on the class body (i.e. !namedScope.isSelf) and so we can skip192 // this instance and resolve to defaultListenerScope upward in the hierarchy.193 // scope: not a named scope so we default to this194 ret = me.getInheritedConfig('defaultListenerScope', hasSkipThis ? skipThis : true) || defaultScope || me;195 } else if (namedScope.isController) {196 // scope:'controller' declared on the class body must include our own197 // controller before ascending the hierarchy, but scope:'controller' declared198 // on the instance must skip our own controller and search only for an199 // inherited controller.200 ret = me.getInheritedConfig('controller', hasSkipThis ? skipThis : !namedScope.isSelf);201 } else if (namedScope.isSelf) {202 // scope:'self' indicates listeners declared on the class body with unspecified203 // scope. Include this instance when searching for an inherited default scope.204 ret = me.getInheritedConfig('defaultListenerScope', hasSkipThis && skipThis) || me;205 } else if (namedScope.isThis) {206 // scope:'this' always resolves to this instance, regardless of whether the207 // listener was declared on the class or instance208 ret = me;209 }210 return ret || null;211 },212 /**213 * Returns the default listener scope for a "satellite" of this component.214 * Used for resolving scope for observable objects that are not part of the normal215 * Container/Component hierarchy (for example, plugins)216 *217 * @param {Ext.mixin.Observable} satellite218 * @param {Object} [defaultScope]219 * @return {Object} The listener scope220 * @protected221 * @since 5.1.1222 */223 resolveSatelliteListenerScope: function(satellite, defaultScope) {224 var me = this,225 namedScope = Ext._namedScopes[defaultScope],226 ret;227 // The logic here is the same as that in resolveListenerScope with a couple of228 // exceptions:229 // 1. If scope resolution failed, fall back to the satellite instance, not "this"230 // for class-declared listeners, for instance-declared use "this"231 // 2. Never pass skipThis to getInheritedConfig. The satellite is essentially232 // treated as a "child" of this component and therefore should always consider233 // its component/component's controller as candidates for listener scope234 if (!namedScope) {235 ret = me.getInheritedConfig('defaultListenerScope') || defaultScope || me;236 } else if (namedScope.isController) {237 ret = me.getInheritedConfig('controller');238 } else if (namedScope.isSelf) {239 ret = me.getInheritedConfig('defaultListenerScope') || satellite;240 } else if (namedScope.isThis) {241 ret = satellite;242 }243 return ret || null;244 },245 /**246 * Gets the Controller or Component that is used as the reference holder for this view.247 *248 * @param {Boolean} [skipThis=true] `false` to return this as the reference holder if249 * this instance has set `referenceHolder`. Unlike `getInheritedConfig` this method250 * defaults to `true` because it is possible that a `reference` property set by the251 * owner of a component that is also a `referenceHolder` itself. In this case, the252 * `reference` connects not to this component but to the parent referenceHolder.253 *254 * @return {Ext.app.ViewController/Ext.container.Container} The reference holder.255 *256 * @private257 * @since 5.0.0258 */259 lookupReferenceHolder: function (skipThis) {260 return this.getInheritedConfig('referenceHolder', skipThis !== false) || null;261 },262 /**263 * Used by {@link Ext.ComponentQuery ComponentQuery}, and the {@link Ext.Component#up up}264 * method to find the owning Component in the linkage hierarchy.265 *266 * By default this returns the Container which contains this Component.267 *268 * This may be overridden by Component authors who implement ownership hierarchies269 * which are not based upon ownerCt, such as BoundLists being owned by Fields or Menus270 * being owned by Buttons.271 * @protected272 */273 getRefOwner: function () {274 // Look for ownerCmp before floatParent for scenarios like a button menu inside a floating window.275 return this.ownerCt || this.initOwnerCt || this.ownerCmp || this.floatParent;276 },277 /**278 * This method is called to initialize the `inheritedState` objects for this instance.279 * This amounts to typically copying certain properties from the instance to the given280 * object.281 *282 * @param {Object} inheritedState The state object for this instance.283 * @param {Object} [inheritedStateInner] This object is only provided for containers.284 * @method initInheritedState285 * @protected286 * @since 5.0.0287 */288 /**289 * This method marks the current inherited state as invalid. The next time a call is290 * made to `getInherited` the objects will be recreated and initialized.291 * @private292 * @since 5.0.0293 */294 invalidateInheritedState: function () {295 var inheritedState = this.inheritedState;296 if (inheritedState) {297 // if component has a inheritedState at this point we set an invalid flag in298 // the inheritedState so descendants of this component know to re-initialize299 // their inheritedState the next time it is requested (see getInherited())300 inheritedState.invalid = true;301 // We can now delete the old inheritedState since it is invalid. IMPORTANT:302 // the descendants are still linked to the old inheritedState via the303 // prototype chain, and their inheritedState property will be synced up304 // the next time their getInherited() method is called. For this reason305 // inheritedState should always be accessed using getInherited()306 delete this.inheritedState;307 }308 }309},310function () {311 /**312 * @property {Object} rootInheritedState313 * The top level inheritedState to which all other inheritedStates are chained. If314 * there is a `Viewport` instance, this object becomes the Viewport's inheritedState.315 * See also {@link Ext.Component#getInherited}.316 *317 * @private318 * @member Ext319 * @since 5.0.0...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';5import { withReadme } from 'storybook-readme';6import { withTests } from '@storybook/addon-jest';7import results from '../../.jest-test-results.json';8import MyComponent from '../src/MyComponent';9import MyComponentReadme from '../src/MyComponent.md';10storiesOf('MyComponent', module)11 .addDecorator(withKnobs)12 .addDecorator(withReadme(MyComponentReadme))13 .addDecorator(withTests({ results }))14 .add('with text', () => (15 <MyComponent>{text('Label', 'Hello Storybook')}</MyComponent>16 .add('with some emoji', () => (17 <MyComponent>{boolean('Label', '😀 😎 👍 💯')}</MyComponent>18 .add('with some number', () => (19 <MyComponent>{number('Label', 1000)}</MyComponent>20 ));21import { configure } from '@storybook/react';22import 'storybook-readme/register';23import 'storybook-addon-jest/register';24import { setDefaults } from '@storybook/addon-info';25import { setOptions } from '@storybook/addon-options';26setOptions({
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { withA11y } from '@storybook/addon-a11y';6import { withTests } from '@storybook/addon-jest';7import { withBackgrounds } from '@storybook/addon-backgrounds';8import { withViewport } from '@storybook/addon-viewport';9import { withConsole } from '@storybook/addon-console';10import { withOptions } from '@storybook/addon-options';11import { withLinks } from '@storybook/addon-links';12import { withStorysource } from '@storybook/addon-storysource';13import { withActions } from '@storybook/addon-actions';14import { withNotes } from '@storybook/addon-notes';15import { withCssResources } from '@storybook/addon-cssresources';16import { withCode } from 'storybook-addon-code';17import { withRoot } from '../src';18const stories = storiesOf('Test', module);19stories.addDecorator(withRoot);20stories.add(21 withInfo({22 })(() => <div>Test</div>)23);24stories.addDecorator(withInfo);25stories.addDecorator(withKnobs);26stories.addDecorator(withA11y);27stories.addDecorator(withTests);28stories.addDecorator(withBackgrounds);29stories.addDecorator(withViewport);30stories.addDecorator(withConsole);31stories.addDecorator(withOptions);32stories.addDecorator(withLinks);33stories.addDecorator(withStorysource);34stories.addDecorator(withActions);35stories.addDecorator(withNotes);36stories.addDecorator(withCssResources);37stories.addDecorator(withCode);38stories.add('Test', () => <div>Test</div>);39import { configure, addDecorator } from '@storybook/react';40import { withRoot } from '../src';41addDecorator(withRoot);42const req = require.context('../src', true, /.stories.js$/);43function loadStories() {44 req.keys().forEach(filename => req(filename));45}46configure(loadStories, module);47import '@storybook/addon-actions/register';48import '@storybook/addon-links/register';49import '@storybook/addon-knobs/register';50import '@storybook/addon-notes/register';51import '@
Using AI Code Generation
1import { storiesOf } from '@storybook/react';2import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';3import { withInfo } from '@storybook/addon-info';4import { action } from '@storybook/addon-actions';5import { linkTo } from '@storybook/addon-links';6import { withA11y } from '@storybook/addon-a11y';7import { withBackgrounds } from '@storybook/addon-backgrounds';8import { withViewport } from '@storybook/addon-viewport';9import { withTests } from '@storybook/addon-jest';10import { withConsole } from '@storybook/addon-console';11import { withOptions } from '@storybook/addon-options';12import { withNotes } from '@storybook/addon-notes';13import { withPropsTable } from 'storybook-addon-react-docgen';14import { withReadme } from 'storybook-readme';15import { withDocs } from 'storybook-readme';16import { withLinks } from '@storybook/addon-links';17import { withStorySource } from '@storybook/addon-storysource';18import { withState } from '@dump247/storybook-state';19import { storiesOf } from '@storybook/react';20import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';21import { withInfo } from '@storybook/addon-info';22import { action } from '@storybook/addon-actions';23import { linkTo } from '@storybook/addon-links';24import { withA11y } from '@storybook/addon-a11y';25import { withBackgrounds } from '@storybook/addon-backgrounds';26import { withViewport } from '@storybook/addon-viewport';27import { withTests } from '@storybook/addon-jest';28import { withConsole } from '@storybook/addon-console';29import { withOptions } from '@storybook/addon-options';30import { withNotes } from '@storybook/addon-notes';31import { withPropsTable } from 'storybook-addon-react-docgen';32import { withReadme } from 'storybook-readme';33import { withDocs } from 'storybook-readme';34import { withLinks } from '@storybook/addon-links';35import { withStorySource } from '@storybook/addon-storysource';36import { withState } from '@dump247/storybook-state';37import { storiesOf } from '@
Using AI Code Generation
1import { withA11y } from '@storybook/addon-a11y';2export default {3};4export const MyStory = () => <div>My story</div>;5MyStory.story = {6};7export const MyStory2 = () => <div>My story</div>;8MyStory2.story = {9};10export const MyStory3 = () => <div>My story</div>;11MyStory3.story = {12};13export const MyStory4 = () => <div>My story</div>;14MyStory4.story = {15};16export const MyStory5 = () => <div>My story</div>;17MyStory5.story = {18};19export const MyStory6 = () => <div>My story</div>;20MyStory6.story = {21};22export const MyStory7 = () => <div>My story</div>;23MyStory7.story = {24};25export const MyStory8 = () => <div>My story</div>;26MyStory8.story = {27};
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!