mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-10 02:03:07 +08:00
fix(nylas-exports): Avoid repeatedly calling require inside lazyLoad
This commit is contained in:
parent
0db70868a8
commit
21303cecb5
1 changed files with 8 additions and 1 deletions
|
@ -2,6 +2,11 @@ TaskRegistry = require('../task-registry').default
|
||||||
StoreRegistry = require('../store-registry').default
|
StoreRegistry = require('../store-registry').default
|
||||||
DatabaseObjectRegistry = require('../database-object-registry').default
|
DatabaseObjectRegistry = require('../database-object-registry').default
|
||||||
|
|
||||||
|
# Calling require() repeatedly isn't free! Even though it has it's own cache,
|
||||||
|
# it still needs to resolve the path to a file based on the current __dirname,
|
||||||
|
# match it against it's cache, etc. We can shortcut all this work.
|
||||||
|
RequireCache = {}
|
||||||
|
|
||||||
class NylasExports
|
class NylasExports
|
||||||
|
|
||||||
@default = (requireValue) -> requireValue.default ? requireValue
|
@default = (requireValue) -> requireValue.default ? requireValue
|
||||||
|
@ -10,7 +15,9 @@ class NylasExports
|
||||||
@lazyLoad = (prop, path) ->
|
@lazyLoad = (prop, path) ->
|
||||||
Object.defineProperty @, prop,
|
Object.defineProperty @, prop,
|
||||||
get: ->
|
get: ->
|
||||||
NylasExports.default(require("../#{path}"))
|
key = "#{prop}#{path}"
|
||||||
|
RequireCache[key] = RequireCache[key] || NylasExports.default(require("../#{path}"))
|
||||||
|
return RequireCache[key]
|
||||||
enumerable: true
|
enumerable: true
|
||||||
|
|
||||||
@lazyLoadCustomGetter = (prop, get) ->
|
@lazyLoadCustomGetter = (prop, get) ->
|
||||||
|
|
Loading…
Reference in a new issue