How to use leafName method in storybook-root

Best JavaScript code snippet using storybook-root

storageService.js

Source:storageService.js Github

copy

Full Screen

1/* See license.txt for terms of usage */2// ********************************************************************************************* //3// Constants4const Cc = Components.classes;5const Ci = Components.interfaces;6const Cr = Components.results;7const Cu = Components.utils;8const dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);9// https://developer.mozilla.org/en/Using_JavaScript_code_modules10var EXPORTED_SYMBOLS = ["Storage", "StorageService", "TextService"];11Cu.import("resource://firebug/fbtrace.js");12Cu.import("resource://gre/modules/FileUtils.jsm");13var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);14try15{16 Cu["import"]("resource://gre/modules/PrivateBrowsingUtils.jsm");17}18catch (err)19{20}21// ********************************************************************************************* //22// Implementation23// xxxHonza: the entire JSM should be converted into AMD.24// But there could be extensions25// see: https://groups.google.com/d/msg/firebug/C5dlQ2S1e0U/ZJ76nxtUAAMJ26/**27 * http://dev.w3.org/html5/webstorage/#storage-028 * interface Storage {29 * readonly attribute unsigned long length;30 * getter DOMString key(in unsigned long index);31 * getter any getItem(in DOMString key);32 * setter creator void setItem(in DOMString key, in any data);33 * deleter void removeItem(in DOMString key);34 * void clear();35 * };36 */37function Storage(leafName, win)38{39 this.leafName = leafName;40 this.win = win;41 this.objectTable = {};42}43Storage.prototype =44{45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //46 // Read47 get length()48 {49 return this.key(-1);50 },51 key: function(index)52 {53 var i = 0;54 for (var p in this.objectTable)55 {56 if (i === index)57 return p;58 i++;59 }60 return (index < 0 ? i : null);61 },62 getItem: function(key)63 {64 return this.objectTable[key];65 },66 getKeys: function()67 {68 var keys = [];69 for (var p in this.objectTable)70 if (this.objectTable.hasOwnProperty(p))71 keys.push(p);72 return keys;73 },74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //75 // Write76 setItem: function(key, data)77 {78 this.objectTable[key] = data;79 StorageService.setStorage(this);80 },81 removeItem: function(key)82 {83 delete this.objectTable[key];84 StorageService.setStorage(this);85 },86 clear: function(now)87 {88 this.objectTable = {};89 StorageService.setStorage(this, now);90 }91};92// ********************************************************************************************* //93/**94 * var store = StorageService.getStorage(leafName);95 * store.setItem("foo", bar); // writes to disk96 */97var StorageService =98{99 getStorage: function(leafName, win)100 {101 var store = new Storage(leafName, win);102 try103 {104 var obj = ObjectPersister.readObject(leafName);105 if (obj)106 store.objectTable = obj;107 }108 catch (err)109 {110 if (FBTrace.DBG_ERRORS || FBTrace.DBG_STORAGE)111 {112 FBTrace.sysout("StorageService.getStorage; EXCEPTION for " + leafName +113 ": " + err, err);114 }115 }116 return store;117 },118 setStorage: function(store, now)119 {120 if (!store || !store.leafName || !store.objectTable)121 throw new Error("StorageService.setStorage requires Storage Object argument");122 // xxxHonza: writeNow() doesn't check private browsing mode, which is not safe.123 // But |now| is currently set to true only in clear() method, which works124 // (and should work I guess) even in private browsing mode.125 if (now)126 ObjectPersister.writeNow(store.leafName, store.objectTable);127 else128 ObjectPersister.writeObject(store.leafName, store.objectTable, store.win);129 },130 removeStorage: function(leafName)131 {132 ObjectPersister.deleteObject(leafName);133 },134 hasStorage: function(leafName)135 {136 var file = ObjectPersister.getFile(leafName);137 return file.exists();138 }139};140// ********************************************************************************************* //141// Implementation142/**143 * @class Represents an internal Firebug persistence service.144 */145var ObjectPersister =146{147 readObject: function(leafName)148 {149 if (FBTrace.DBG_STORAGE)150 FBTrace.sysout("ObjectPersister read from leafName "+leafName);151 var file = this.getFile(leafName);152 if (!file.exists())153 {154 file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);155 if (FBTrace.DBG_STORAGE)156 FBTrace.sysout("ObjectPersister.readTextFromFile file created " + file.path);157 return;158 }159 var obj = this.readObjectFromFile(file);160 return obj;161 },162 readObjectFromFile: function(file)163 {164 var text = ObjectPersister.readTextFromFile(file);165 if (!text)166 return null;167 var obj = JSON.parse(text);168 if (!obj)169 return;170 if (FBTrace.DBG_STORAGE)171 FBTrace.sysout("PersistedObject loaded from " + file.path+" got text "+text, obj);172 return obj;173 },174 readTextFromFile: function(file)175 {176 try177 {178 var inputStream = Cc["@mozilla.org/network/file-input-stream;1"]179 .createInstance(Ci.nsIFileInputStream);180 var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"]181 .createInstance(Ci.nsIConverterInputStream);182 // Initialize input stream.183 inputStream.init(file, 0x01 | 0x08, 0666, 0); // read, create184 cstream.init(inputStream, "UTF-8", 0, 0);185 // Load json.186 var json = "";187 var data = {};188 while (cstream.readString(-1, data) != 0)189 json += data.value;190 inputStream.close();191 return json;192 }193 catch (err)194 {195 if (FBTrace.DBG_ERRORS || FBTrace.DBG_STORAGE)196 FBTrace.sysout("ObjectPersister.initialize; EXCEPTION", err);197 }198 },199 getFile: function(leafName)200 {201 return FileUtils.getFile("ProfD", ["firebug", leafName]);202 },203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //204 // Batch the writes for each event loop205 writeDelay: 250,206 writeObject: function(leafName, obj, win)207 {208 if (this.isPrivateBrowsing(win))209 return;210 // xxxHonza: see https://code.google.com/p/fbug/issues/detail?id=7561#c8211 //throw new Error("No storage is written while in private browsing mode");212 if (ObjectPersister.flushTimeout)213 return;214 ObjectPersister.flushTimeout = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);215 var writeOnTimeout = ObjectPersister.getWriteOnTimeout(leafName, obj);216 ObjectPersister.flushTimeout.init(writeOnTimeout, ObjectPersister.writeDelay,217 Ci.nsITimer.TYPE_ONE_SHOT);218 },219 getWriteOnTimeout: function(leafName, obj)220 {221 var writerClosure =222 {223 leafName: leafName,224 obj: obj,225 observe: function(timer, topic, data)226 {227 ObjectPersister.writeNow(writerClosure.leafName, writerClosure.obj);228 delete ObjectPersister.flushTimeout;229 }230 };231 return writerClosure;232 },233 writeNow: function(leafName, obj)234 {235 try236 {237 // Convert data to JSON.238 var jsonString = JSON.stringify(obj);239 var file = this.getFile(leafName);240 ObjectPersister.writeTextToFile(file, jsonString);241 }242 catch(exc)243 {244 if (FBTrace.DBG_ERRORS || FBTrace.DBG_STORAGE)245 FBTrace.sysout("ObjectPersister.writeNow; EXCEPTION for " + leafName + ": " +246 exc, {exception: exc, obj: obj});247 }248 },249 writeTextToFile: function(file, string)250 {251 try252 {253 // Initialize output stream.254 var outputStream = Cc["@mozilla.org/network/file-output-stream;1"]255 .createInstance(Ci.nsIFileOutputStream);256 outputStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0); // write, create, truncate257 // Store JSON258 outputStream.write(string, string.length);259 outputStream.close();260 if (FBTrace.DBG_STORAGE)261 FBTrace.sysout("ObjectPersister.writeNow to " + file.path, string);262 return file.path;263 }264 catch (err)265 {266 if (FBTrace.DBG_ERRORS || FBTrace.DBG_STORAGE)267 FBTrace.sysout("ObjectPersister.writeTextToFile; EXCEPTION for " + file.path +268 ": "+err, {exception: err, string: string});269 }270 },271 deleteObject: function(leafName)272 {273 var file = this.getFile(leafName);274 return file.remove(false);275 },276 // xxxHonza: this entire method is duplicated from firebug/lib/privacy module277 // As soon as this JSM is AMD we should just use firebug/lib/privacy.278 isPrivateBrowsing: function(win)279 {280 try281 {282 // If |win| is null, the top most window is used to figure out283 // whether the private mode is on or off.284 if (!win)285 win = wm.getMostRecentWindow("navigator:browser");286 }287 catch (e)288 {289 if (FBTrace.DBG_ERRORS)290 FBTrace.sysout("storageService.isPrivateBrowsing; EXCEPTION " + e, e);291 }292 try293 {294 // Get firebugFrame.xul and check privaate mode (it's the same as295 // for the top parent window).296 if (typeof PrivateBrowsingUtils != "undefined")297 return PrivateBrowsingUtils.isWindowPrivate(win);298 }299 catch (e)300 {301 }302 try303 {304 // Unfortunatelly the "firebug/chrome/privacy" module can't be used305 // since this scope is JavaScript code module.306 // xxxHonza: storageService should be converted into AMD (but it's used307 // in firebug-service.js, which is also JS code module).308 // firebug-service.js is gone in JSD2 branch309 var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]310 .getService(Components.interfaces.nsIPrivateBrowsingService);311 return pbs.privateBrowsingEnabled;312 }313 catch (e)314 {315 }316 return false;317 }318};319// ********************************************************************************************* //320var TextService =321{322 readText: ObjectPersister.readTextFromFile,323 writeText: ObjectPersister.writeTextToFile324};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { leafName } from 'storybook-root';2import { leafName } from 'storybook-root';3import { leafName } from 'storybook-root';4import { leafName } from 'storybook-root';5import { leafName } from 'storybook-root';6import { leafName } from 'storybook-root';7import { leafName } from 'storybook-root';8import { leafName } from 'storybook-root';9import { leafName } from 'storybook-root';10import { leafName } from 'storybook-root';11import { leafName } from 'storybook-root';12import { leafName } from 'storybook-root';13import { leafName } from 'storybook-root';14import { leafName } from 'storybook-root';15import { leafName } from 'storybook-root';16import { leafName } from 'storybook-root';17import { leafName } from 'storybook-root';18import { leafName } from 'storybook-root';19import { leafName } from 'storybook-root';20import { leafName } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { leafName } from 'storybook-root';2console.log(leafName);3export { default as leafName } from './leafName';4export default 'leafName';5import { leafName } from 'storybook-root';6describe('leafName', () => {7 it('should return leafName', () => {8 expect(leafName).toEqual('leafName');9 });10});11{12}13"jest": {14 "transform": {15 }16 }17{

Full Screen

Using AI Code Generation

copy

Full Screen

1import {leafName} from 'storybook-root'2console.log(leafName)3export {leafName} from './test'4export {leafName} from './test'5export {leafName} from './test'6export {leafName} from './test'7export {leafName} from './test'8export {leafName} from './test'9export {leafName} from './test'10export {leafName} from './test'11export {leafName} from './test'

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