Remove q promise library, trim down reflux a bit

This commit is contained in:
Ben Gotow 2017-07-10 13:25:42 -07:00
parent 25df062f55
commit c2d192c1a3
13 changed files with 37 additions and 103 deletions

View file

@ -63,7 +63,6 @@
"pathwatcher": "~6.2",
"pick-react-known-prop": "0.x.x",
"proxyquire": "1.3.1",
"q": "^1.0.1",
"raven": "1.1.4",
"react": "15.6.1",
"react-addons-css-transition-group": "15.6.1",

View file

@ -1,4 +1,3 @@
Reflux = require 'reflux'
Actions = require('../src/flux/actions').default
Message = require('../src/flux/models/message').default
DatabaseStore = require('../src/flux/stores/database-store').default

View file

@ -1,5 +1,4 @@
proxyquire = require 'proxyquire'
Reflux = require 'reflux'
FocusedContactsStore = require '../../src/flux/stores/focused-contacts-store'

View file

@ -1,49 +1,8 @@
_ = require('underscore')
_str = require('underscore.string')
EventEmitter = require('events').EventEmitter
callbackName = (string) ->
"on"+string.charAt(0).toUpperCase()+string.slice(1)
###*
# Extract child listenables from a parent from their
# children property and return them in a keyed Object
#
# @param {Object} listenable The parent listenable
###
mapChildListenables = (listenable) ->
i = 0
children = {}
childName = undefined
while i < (listenable.children or []).length
childName = listenable.children[i]
if listenable[childName]
children[childName] = listenable[childName]
++i
children
###*
# Make a flat dictionary of all listenables including their
# possible children (recursively), concatenating names in camelCase.
#
# @param {Object} listenables The top-level listenables
###
flattenListenables = (listenables) ->
flattened = {}
for key of listenables
listenable = listenables[key]
childMap = mapChildListenables(listenable)
# recursively flatten children
children = flattenListenables(childMap)
# add the primary listenable and chilren
flattened[key] = listenable
for childKey of children
childListenable = children[childKey]
flattened[key + _str.capitalize(childKey)] = childListenable
flattened
module.exports =
@ -64,19 +23,10 @@ module.exports =
++i
false
listenToMany: (listenables) ->
allListenables = flattenListenables(listenables)
for key of allListenables
cbname = callbackName(key)
localname = if @[cbname] then cbname else if @[key] then key else undefined
if localname
@listenTo allListenables[key], localname, @[cbname + 'Default'] or @[localname + 'Default'] or localname
return
validateListening: (listenable) ->
if listenable == this
return 'Listener is not able to listen to itself'
if !_.isFunction(listenable.listen)
if not (listenable.listen instanceof Function)
console.log require('util').inspect(listenable)
console.log((new Error()).stack)
return listenable + ' is missing a listen method'
@ -138,9 +88,9 @@ module.exports =
fetchInitialState: (listenable, defaultCallback) ->
defaultCallback = defaultCallback and @[defaultCallback] or defaultCallback
me = this
if _.isFunction(defaultCallback) and _.isFunction(listenable.getInitialState)
if defaultCallback instanceof Function and listenable.getInitialState instanceof Function
data = listenable.getInitialState()
if data and _.isFunction(data.then)
if data and data.then instanceof Function
data.then ->
defaultCallback.apply me, arguments
return

View file

@ -1,6 +1,5 @@
fs = require 'fs'
path = require 'path'
Reflux = require 'reflux'
Rx = require 'rx-lite'
Actions = require('../actions').default
Contact = require('../models/contact').default

View file

@ -1,5 +1,4 @@
_ = require 'underscore'
Reflux = require 'reflux'
AccountStore = require('./account-store').default
WorkspaceStore = require './workspace-store'
DatabaseStore = require('./database-store').default

View file

@ -165,7 +165,6 @@ lazyLoad(`ContenteditableExtension`, 'extensions/contenteditable-extension');
// 3rd party libraries
lazyLoadWithGetter(`Rx`, () => require('rx-lite'));
lazyLoadWithGetter(`React`, () => require('react'));
lazyLoadWithGetter(`Reflux`, () => require('reflux'));
lazyLoadWithGetter(`ReactDOM`, () => require('react-dom'));
lazyLoadWithGetter(`ReactTestUtils`, () => require('react-dom/test-utils'));

View file

@ -554,7 +554,7 @@ class PackageManager
for [activator, types] in @packageActivators
packages = @getLoadedPackagesForTypes(types)
promises = promises.concat(activator.activatePackages(packages))
Q.all(promises).then =>
Promise.all(promises).then =>
@emit 'activated'
@emitter.emit 'did-activate-initial-packages'
@ -578,7 +578,7 @@ class PackageManager
# Activate a single package by name
activatePackage: (name) ->
if pack = @getActivePackage(name)
Q(pack)
Promise.resolve(pack)
else if pack = @loadPackage(name)
pack.activate().then =>
@activePackages[pack.name] = pack
@ -586,7 +586,7 @@ class PackageManager
@onPluginsChanged()
pack
else
Q.reject(new Error("Failed to load package '#{name}'"))
Promise.reject(new Error("Failed to load package '#{name}'"))
# Deactivate all packages
deactivatePackages: ->

View file

@ -142,13 +142,12 @@ class Package
@menus = []
activate: ->
unless @activationDeferred?
@activationDeferred = Q.defer()
unless @isActivated
@measure 'activateTime', =>
@activateResources()
@activateNow()
Q.all([@activationDeferred.promise])
@isActivated = true
return Promise.resolve()
activateNow: ->
try
@ -163,8 +162,6 @@ class Package
console.error e.stack
console.warn "Failed to activate package named '#{@name}'", e.stack
@activationDeferred?.resolve()
activateConfig: ->
return if @configActivated
@ -262,8 +259,7 @@ class Package
console.error "Error serializing package '#{@name}'", e.stack
deactivate: ->
@activationDeferred?.reject()
@activationDeferred = null
@isActivated = null
@deactivateResources()
@deactivateConfig()
if @mainActivated

View file

@ -52,7 +52,7 @@ class SanitizeTransformer {
}
if (!sanitizeHtml) {
sanitizeHtml = require('sanitize-html').default; //eslint-disable-line
sanitizeHtml = require('sanitize-html'); //eslint-disable-line
}
return Promise.resolve(sanitizeHtml(body, settings));
}

View file

@ -1,4 +1,3 @@
fs = require 'fs-plus'
path = require 'path'
{Emitter, Disposable} = require 'event-kit'

View file

@ -233,32 +233,29 @@ class ThemeManager
string.replace(/\\/g, '/')
activateThemes: ->
deferred = Q.defer()
return new Promise (resolve) =>
# NylasEnv.config.observe runs the callback once, then on subsequent changes.
NylasEnv.config.observe 'core.themes', =>
@deactivateThemes()
# NylasEnv.config.observe runs the callback once, then on subsequent changes.
NylasEnv.config.observe 'core.themes', =>
@deactivateThemes()
# Refreshing the less cache is very expensive (hundreds of ms). It
# will be refreshed once the promise resolves after packages are
# activated.
# Refreshing the less cache is very expensive (hundreds of ms). It
# will be refreshed once the promise resolves after packages are
# activated.
promises = []
for themeName in @getEnabledThemeNames()
if @packageManager.resolvePackagePath(themeName)
promises.push(@packageManager.activatePackage(themeName))
else
console.warn("Failed to activate theme '#{themeName}' because it isn't installed.")
promises = []
for themeName in @getEnabledThemeNames()
if @packageManager.resolvePackagePath(themeName)
promises.push(@packageManager.activatePackage(themeName))
else
console.warn("Failed to activate theme '#{themeName}' because it isn't installed.")
Q.all(promises).then =>
@addActiveThemeClasses()
@refreshLessCache() # Update cache again now that @getActiveThemes() is populated
@reloadBaseStylesheets()
@initialLoadComplete = true
@emitter.emit 'did-change-active-themes'
deferred.resolve()
deferred.promise
Promise.all(promises).then =>
@addActiveThemeClasses()
@refreshLessCache() # Update cache again now that @getActiveThemes() is populated
@reloadBaseStylesheets()
@initialLoadComplete = true
@emitter.emit 'did-change-active-themes'
resolve()
deactivateThemes: ->
@removeActiveThemeClasses()

View file

@ -22,11 +22,9 @@ class ThemePackage extends Package
this
activate: ->
return @activationDeferred.promise if @activationDeferred?
@activationDeferred = Q.defer()
@measure 'activateTime', =>
@loadStylesheets()
@activateNow()
@activationDeferred.promise
unless @isActivated
@measure 'activateTime', =>
@loadStylesheets()
@activateNow()
@isActivated = true
return Promise.resolve()