mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-22 04:25:36 +08:00
perf(require): Don't assume require
is free, cache deferred imports
This commit is contained in:
parent
f396d9eddb
commit
c460a4f2a4
8 changed files with 19 additions and 14 deletions
|
@ -1,6 +1,8 @@
|
|||
ModelWithMetadata = require './model-with-metadata'
|
||||
Attributes = require '../attributes'
|
||||
_ = require 'underscore'
|
||||
CategoryStore = null
|
||||
Contact = null
|
||||
|
||||
###
|
||||
Public: The Account model represents a Account served by the Nylas Platform API.
|
||||
|
@ -80,14 +82,14 @@ class Account extends ModelWithMetadata
|
|||
|
||||
# Returns a {Contact} model that represents the current user.
|
||||
me: ->
|
||||
Contact = require './contact'
|
||||
Contact ?= require './contact'
|
||||
return new Contact
|
||||
accountId: @id
|
||||
name: @name
|
||||
email: @emailAddress
|
||||
|
||||
meUsingAlias: (alias) ->
|
||||
Contact = require './contact'
|
||||
Contact ?= require './contact'
|
||||
return @me() unless alias
|
||||
return Contact.fromString(alias, accountId: @id)
|
||||
|
||||
|
@ -133,15 +135,15 @@ class Account extends ModelWithMetadata
|
|||
return @provider
|
||||
|
||||
canArchiveThreads: ->
|
||||
CategoryStore = require '../stores/category-store'
|
||||
CategoryStore ?= require '../stores/category-store'
|
||||
CategoryStore.getArchiveCategory(@)?
|
||||
|
||||
canTrashThreads: ->
|
||||
CategoryStore = require '../stores/category-store'
|
||||
CategoryStore ?= require '../stores/category-store'
|
||||
CategoryStore.getTrashCategory(@)?
|
||||
|
||||
defaultFinishedCategory: ->
|
||||
CategoryStore = require '../stores/category-store'
|
||||
CategoryStore ?= require '../stores/category-store'
|
||||
preferDelete = NylasEnv.config.get('core.reading.backspaceDelete')
|
||||
archiveCategory = CategoryStore.getArchiveCategory(@)
|
||||
trashCategory = CategoryStore.getTrashCategory(@)
|
||||
|
|
|
@ -3,6 +3,7 @@ Model = require './model'
|
|||
Actions = require '../actions'
|
||||
Attributes = require '../attributes'
|
||||
_ = require 'underscore'
|
||||
RegExpUtils = null
|
||||
|
||||
###
|
||||
Public: File model represents a File object served by the Nylas Platform API.
|
||||
|
@ -68,7 +69,7 @@ class File extends Model
|
|||
return "Unnamed Attachment"
|
||||
|
||||
safeDisplayName: ->
|
||||
RegExpUtils = require '../../regexp-utils'
|
||||
RegExpUtils ?= require '../../regexp-utils'
|
||||
return @displayName().replace(RegExpUtils.illegalPathCharactersRegexp(), '-')
|
||||
|
||||
# Public: Returns the file extension that should be used for this file.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
_ = require 'underscore'
|
||||
QuerySubscription = require './query-subscription'
|
||||
DatabaseStore = null
|
||||
|
||||
###
|
||||
Public: The QuerySubscriptionPool maintains a list of all of the query
|
||||
|
@ -75,7 +76,7 @@ class QuerySubscriptionPool
|
|||
return query.sql()
|
||||
|
||||
_setup: =>
|
||||
DatabaseStore = require '../stores/database-store'
|
||||
DatabaseStore ?= require '../stores/database-store'
|
||||
DatabaseStore.listen @_onChange
|
||||
|
||||
_onChange: (record) =>
|
||||
|
|
|
@ -305,7 +305,6 @@ class NylasAPI
|
|||
|
||||
# Step 3: Retrieve any existing models from the database for the given IDs.
|
||||
ids = _.pluck(unlockedJSONs, 'id')
|
||||
DatabaseStore = require './stores/database-store'
|
||||
DatabaseStore.findAll(klass).where(klass.attributes.id.in(ids)).then (models) ->
|
||||
existingModels = {}
|
||||
existingModels[model.id] = model for model in models
|
||||
|
|
|
@ -13,6 +13,7 @@ PriorityUICoordinator = require '../../priority-ui-coordinator'
|
|||
DatabaseSetupQueryBuilder = require './database-setup-query-builder'
|
||||
DatabaseChangeRecord = require './database-change-record'
|
||||
DatabaseTransaction = require './database-transaction'
|
||||
JSONBlob = null
|
||||
|
||||
{ipcRenderer} = require 'electron'
|
||||
|
||||
|
@ -436,7 +437,7 @@ class DatabaseStore extends NylasStore
|
|||
Promise.resolve(result)
|
||||
|
||||
findJSONBlob: (id) ->
|
||||
JSONBlob = require '../models/json-blob'
|
||||
JSONBlob ?= require '../models/json-blob'
|
||||
new JSONBlobQuery(JSONBlob, @).where({id}).one()
|
||||
|
||||
# Private: Mutation hooks allow you to observe changes to the database and
|
||||
|
|
|
@ -6,6 +6,7 @@ AccountStore = require './account-store'
|
|||
ContactStore = require './contact-store'
|
||||
MessageStore = require './message-store'
|
||||
FocusedPerspectiveStore = require './focused-perspective-store'
|
||||
DraftStore = null
|
||||
|
||||
InlineStyleTransformer = require '../../services/inline-style-transformer'
|
||||
SanitizeTransformer = require '../../services/sanitize-transformer'
|
||||
|
@ -166,7 +167,7 @@ class DraftFactory
|
|||
return Promise.resolve(candidateDrafts.pop())
|
||||
|
||||
else if behavior is 'prefer-existing-if-pristine'
|
||||
DraftStore = require './draft-store'
|
||||
DraftStore ?= require './draft-store'
|
||||
return Promise.all(candidateDrafts.map (candidateDraft) =>
|
||||
DraftStore.sessionForClientId(candidateDraft.clientId)
|
||||
).then (sessions) =>
|
||||
|
|
|
@ -5,6 +5,7 @@ ExtensionRegistry = require '../../extension-registry'
|
|||
{Listener, Publisher} = require '../modules/reflux-coffee'
|
||||
SyncbackDraftTask = require '../tasks/syncback-draft-task'
|
||||
CoffeeHelpers = require '../coffee-helpers'
|
||||
DraftStore = null
|
||||
|
||||
_ = require 'underscore'
|
||||
|
||||
|
@ -93,7 +94,7 @@ class DraftStoreProxy
|
|||
@include Listener
|
||||
|
||||
constructor: (@draftClientId, draft = null) ->
|
||||
DraftStore = require './draft-store'
|
||||
DraftStore ?= require './draft-store'
|
||||
@listenTo DraftStore, @_onDraftChanged
|
||||
|
||||
@_draft = false
|
||||
|
@ -144,8 +145,6 @@ class DraftStoreProxy
|
|||
|
||||
# Reverse draft transformations performed by third-party plugins when the draft
|
||||
# was last saved to disk
|
||||
DraftStore = require './draft-store'
|
||||
|
||||
return Promise.each ExtensionRegistry.Composer.extensions(), (ext) ->
|
||||
if ext.applyTransformsToDraft and ext.unapplyTransformsToDraft
|
||||
Promise.resolve(ext.unapplyTransformsToDraft({draft})).then (untransformed) ->
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
RegExpUtils = require '../regexp-utils'
|
||||
crypto = require 'crypto'
|
||||
_ = require 'underscore'
|
||||
userAgentDefault = null
|
||||
|
||||
class InlineStyleTransformer
|
||||
constructor: ->
|
||||
|
@ -34,7 +35,7 @@ class InlineStyleTransformer
|
|||
i = body.search(RegExpUtils.looseStyleTag())
|
||||
return body if i is -1
|
||||
|
||||
userAgentDefault = require '../chrome-user-agent-stylesheet-string'
|
||||
userAgentDefault ?= require '../chrome-user-agent-stylesheet-string'
|
||||
return "#{body[0...i]}<style>#{userAgentDefault}</style>#{body[i..-1]}"
|
||||
|
||||
_onInlineStylesResult: (event, {html, key}) =>
|
||||
|
|
Loading…
Add table
Reference in a new issue