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