mirror of
https://github.com/atom/atom.git
synced 2026-01-26 15:28:27 -05:00
Merge pull request #17938 from atom/mb-decaf-classes-with-deserializers
Fix classes whose constructor name was broken by minification
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -5430,9 +5430,9 @@
|
||||
}
|
||||
},
|
||||
"text-buffer": {
|
||||
"version": "13.14.6",
|
||||
"resolved": "https://registry.npmjs.org/text-buffer/-/text-buffer-13.14.6.tgz",
|
||||
"integrity": "sha512-CC2uyrnn+bZXIOVtXMR8jNPyrfciPGMjfyKBY9BkenbtQc06vHy9QvBhkDRf0kY/J1uCD3sJ/cbV6OV7yYM/Sw==",
|
||||
"version": "13.14.8",
|
||||
"resolved": "https://registry.npmjs.org/text-buffer/-/text-buffer-13.14.8.tgz",
|
||||
"integrity": "sha512-hl2adF6WZf4fjy1AuIRZtPqRQ6in9V+KSM7I5eUp0FEI/PBH1EwaTzO1UWrnslI7Lybiiwx4TELOQXOVjFqfQg==",
|
||||
"requires": {
|
||||
"delegato": "^1.0.0",
|
||||
"diff": "^2.2.1",
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
"symbols-view": "https://www.atom.io/api/packages/symbols-view/versions/0.118.2/tarball",
|
||||
"tabs": "https://www.atom.io/api/packages/tabs/versions/0.109.2/tarball",
|
||||
"temp": "^0.8.3",
|
||||
"text-buffer": "13.14.6",
|
||||
"text-buffer": "13.14.8",
|
||||
"timecop": "https://www.atom.io/api/packages/timecop/versions/0.36.2/tarball",
|
||||
"tree-sitter": "0.13.8",
|
||||
"tree-view": "https://www.atom.io/api/packages/tree-view/versions/0.224.2/tarball",
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
{Emitter, CompositeDisposable} = require 'event-kit'
|
||||
{flatten} = require 'underscore-plus'
|
||||
Model = require './model'
|
||||
PaneAxisElement = require './pane-axis-element'
|
||||
|
||||
module.exports =
|
||||
class PaneAxis extends Model
|
||||
parent: null
|
||||
container: null
|
||||
orientation: null
|
||||
|
||||
@deserialize: (state, {deserializers, views}) ->
|
||||
state.children = state.children.map (childState) ->
|
||||
deserializers.deserialize(childState)
|
||||
new this(state, views)
|
||||
|
||||
constructor: ({@orientation, children, flexScale}, @viewRegistry) ->
|
||||
@emitter = new Emitter
|
||||
@subscriptionsByChild = new WeakMap
|
||||
@subscriptions = new CompositeDisposable
|
||||
@children = []
|
||||
if children?
|
||||
@addChild(child) for child in children
|
||||
@flexScale = flexScale ? 1
|
||||
|
||||
serialize: ->
|
||||
deserializer: 'PaneAxis'
|
||||
children: @children.map (child) -> child.serialize()
|
||||
orientation: @orientation
|
||||
flexScale: @flexScale
|
||||
|
||||
getElement: ->
|
||||
@element ?= new PaneAxisElement().initialize(this, @viewRegistry)
|
||||
|
||||
getFlexScale: -> @flexScale
|
||||
|
||||
setFlexScale: (@flexScale) ->
|
||||
@emitter.emit 'did-change-flex-scale', @flexScale
|
||||
@flexScale
|
||||
|
||||
getParent: -> @parent
|
||||
|
||||
setParent: (@parent) -> @parent
|
||||
|
||||
getContainer: -> @container
|
||||
|
||||
setContainer: (container) ->
|
||||
if container and container isnt @container
|
||||
@container = container
|
||||
child.setContainer(container) for child in @children
|
||||
|
||||
getOrientation: -> @orientation
|
||||
|
||||
getChildren: -> @children.slice()
|
||||
|
||||
getPanes: ->
|
||||
flatten(@children.map (child) -> child.getPanes())
|
||||
|
||||
getItems: ->
|
||||
flatten(@children.map (child) -> child.getItems())
|
||||
|
||||
onDidAddChild: (fn) ->
|
||||
@emitter.on 'did-add-child', fn
|
||||
|
||||
onDidRemoveChild: (fn) ->
|
||||
@emitter.on 'did-remove-child', fn
|
||||
|
||||
onDidReplaceChild: (fn) ->
|
||||
@emitter.on 'did-replace-child', fn
|
||||
|
||||
onDidDestroy: (fn) ->
|
||||
@emitter.once 'did-destroy', fn
|
||||
|
||||
onDidChangeFlexScale: (fn) ->
|
||||
@emitter.on 'did-change-flex-scale', fn
|
||||
|
||||
observeFlexScale: (fn) ->
|
||||
fn(@flexScale)
|
||||
@onDidChangeFlexScale(fn)
|
||||
|
||||
addChild: (child, index=@children.length) ->
|
||||
@children.splice(index, 0, child)
|
||||
child.setParent(this)
|
||||
child.setContainer(@container)
|
||||
@subscribeToChild(child)
|
||||
@emitter.emit 'did-add-child', {child, index}
|
||||
|
||||
adjustFlexScale: ->
|
||||
# get current total flex scale of children
|
||||
total = 0
|
||||
total += child.getFlexScale() for child in @children
|
||||
|
||||
needTotal = @children.length
|
||||
# set every child's flex scale by the ratio
|
||||
for child in @children
|
||||
child.setFlexScale(needTotal * child.getFlexScale() / total)
|
||||
|
||||
removeChild: (child, replacing=false) ->
|
||||
index = @children.indexOf(child)
|
||||
throw new Error("Removing non-existent child") if index is -1
|
||||
|
||||
@unsubscribeFromChild(child)
|
||||
|
||||
@children.splice(index, 1)
|
||||
@adjustFlexScale()
|
||||
@emitter.emit 'did-remove-child', {child, index}
|
||||
@reparentLastChild() if not replacing and @children.length < 2
|
||||
|
||||
replaceChild: (oldChild, newChild) ->
|
||||
@unsubscribeFromChild(oldChild)
|
||||
@subscribeToChild(newChild)
|
||||
|
||||
newChild.setParent(this)
|
||||
newChild.setContainer(@container)
|
||||
|
||||
index = @children.indexOf(oldChild)
|
||||
@children.splice(index, 1, newChild)
|
||||
@emitter.emit 'did-replace-child', {oldChild, newChild, index}
|
||||
|
||||
insertChildBefore: (currentChild, newChild) ->
|
||||
index = @children.indexOf(currentChild)
|
||||
@addChild(newChild, index)
|
||||
|
||||
insertChildAfter: (currentChild, newChild) ->
|
||||
index = @children.indexOf(currentChild)
|
||||
@addChild(newChild, index + 1)
|
||||
|
||||
reparentLastChild: ->
|
||||
lastChild = @children[0]
|
||||
lastChild.setFlexScale(@flexScale)
|
||||
@parent.replaceChild(this, lastChild)
|
||||
@destroy()
|
||||
|
||||
subscribeToChild: (child) ->
|
||||
subscription = child.onDidDestroy => @removeChild(child)
|
||||
@subscriptionsByChild.set(child, subscription)
|
||||
@subscriptions.add(subscription)
|
||||
|
||||
unsubscribeFromChild: (child) ->
|
||||
subscription = @subscriptionsByChild.get(child)
|
||||
@subscriptions.remove(subscription)
|
||||
subscription.dispose()
|
||||
|
||||
destroyed: ->
|
||||
@subscriptions.dispose()
|
||||
@emitter.emit 'did-destroy'
|
||||
@emitter.dispose()
|
||||
199
src/pane-axis.js
Normal file
199
src/pane-axis.js
Normal file
@@ -0,0 +1,199 @@
|
||||
const {Emitter, CompositeDisposable} = require('event-kit')
|
||||
const {flatten} = require('underscore-plus')
|
||||
const Model = require('./model')
|
||||
const PaneAxisElement = require('./pane-axis-element')
|
||||
|
||||
class PaneAxis extends Model {
|
||||
static deserialize (state, {deserializers, views}) {
|
||||
state.children = state.children.map(childState => deserializers.deserialize(childState))
|
||||
return new PaneAxis(state, views)
|
||||
}
|
||||
|
||||
constructor ({orientation, children, flexScale}, viewRegistry) {
|
||||
super()
|
||||
this.parent = null
|
||||
this.container = null
|
||||
this.orientation = orientation
|
||||
this.viewRegistry = viewRegistry
|
||||
this.emitter = new Emitter()
|
||||
this.subscriptionsByChild = new WeakMap()
|
||||
this.subscriptions = new CompositeDisposable()
|
||||
this.flexScale = flexScale != null ? flexScale : 1
|
||||
this.children = []
|
||||
if (children) {
|
||||
for (let child of children) {
|
||||
this.addChild(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serialize () {
|
||||
return {
|
||||
deserializer: 'PaneAxis',
|
||||
children: this.children.map(child => child.serialize()),
|
||||
orientation: this.orientation,
|
||||
flexScale: this.flexScale
|
||||
}
|
||||
}
|
||||
|
||||
getElement () {
|
||||
if (!this.element) {
|
||||
this.element = new PaneAxisElement().initialize(this, this.viewRegistry)
|
||||
}
|
||||
return this.element
|
||||
}
|
||||
|
||||
getFlexScale () {
|
||||
return this.flexScale
|
||||
}
|
||||
|
||||
setFlexScale (flexScale) {
|
||||
this.flexScale = flexScale
|
||||
this.emitter.emit('did-change-flex-scale', this.flexScale)
|
||||
return this.flexScale
|
||||
}
|
||||
|
||||
getParent () {
|
||||
return this.parent
|
||||
}
|
||||
|
||||
setParent (parent) {
|
||||
this.parent = parent
|
||||
return this.parent
|
||||
}
|
||||
|
||||
getContainer () {
|
||||
return this.container
|
||||
}
|
||||
|
||||
setContainer (container) {
|
||||
if (container && (container !== this.container)) {
|
||||
this.container = container
|
||||
this.children.forEach(child => child.setContainer(container))
|
||||
}
|
||||
}
|
||||
|
||||
getOrientation () {
|
||||
return this.orientation
|
||||
}
|
||||
|
||||
getChildren () {
|
||||
return this.children.slice()
|
||||
}
|
||||
|
||||
getPanes () {
|
||||
return flatten(this.children.map(child => child.getPanes()))
|
||||
}
|
||||
|
||||
getItems () {
|
||||
return flatten(this.children.map(child => child.getItems()))
|
||||
}
|
||||
|
||||
onDidAddChild (fn) {
|
||||
return this.emitter.on('did-add-child', fn)
|
||||
}
|
||||
|
||||
onDidRemoveChild (fn) {
|
||||
return this.emitter.on('did-remove-child', fn)
|
||||
}
|
||||
|
||||
onDidReplaceChild (fn) {
|
||||
return this.emitter.on('did-replace-child', fn)
|
||||
}
|
||||
|
||||
onDidDestroy (fn) {
|
||||
return this.emitter.once('did-destroy', fn)
|
||||
}
|
||||
|
||||
onDidChangeFlexScale (fn) {
|
||||
return this.emitter.on('did-change-flex-scale', fn)
|
||||
}
|
||||
|
||||
observeFlexScale (fn) {
|
||||
fn(this.flexScale)
|
||||
return this.onDidChangeFlexScale(fn)
|
||||
}
|
||||
|
||||
addChild (child, index = this.children.length) {
|
||||
this.children.splice(index, 0, child)
|
||||
child.setParent(this)
|
||||
child.setContainer(this.container)
|
||||
this.subscribeToChild(child)
|
||||
return this.emitter.emit('did-add-child', {child, index})
|
||||
}
|
||||
|
||||
adjustFlexScale () {
|
||||
// get current total flex scale of children
|
||||
let total = 0
|
||||
for (var child of this.children) { total += child.getFlexScale() }
|
||||
|
||||
const needTotal = this.children.length
|
||||
// set every child's flex scale by the ratio
|
||||
for (child of this.children) {
|
||||
child.setFlexScale((needTotal * child.getFlexScale()) / total)
|
||||
}
|
||||
}
|
||||
|
||||
removeChild (child, replacing = false) {
|
||||
const index = this.children.indexOf(child)
|
||||
if (index === -1) { throw new Error('Removing non-existent child') }
|
||||
|
||||
this.unsubscribeFromChild(child)
|
||||
|
||||
this.children.splice(index, 1)
|
||||
this.adjustFlexScale()
|
||||
this.emitter.emit('did-remove-child', {child, index})
|
||||
if (!replacing && this.children.length < 2) {
|
||||
this.reparentLastChild()
|
||||
}
|
||||
}
|
||||
|
||||
replaceChild (oldChild, newChild) {
|
||||
this.unsubscribeFromChild(oldChild)
|
||||
this.subscribeToChild(newChild)
|
||||
|
||||
newChild.setParent(this)
|
||||
newChild.setContainer(this.container)
|
||||
|
||||
const index = this.children.indexOf(oldChild)
|
||||
this.children.splice(index, 1, newChild)
|
||||
this.emitter.emit('did-replace-child', {oldChild, newChild, index})
|
||||
}
|
||||
|
||||
insertChildBefore (currentChild, newChild) {
|
||||
const index = this.children.indexOf(currentChild)
|
||||
return this.addChild(newChild, index)
|
||||
}
|
||||
|
||||
insertChildAfter (currentChild, newChild) {
|
||||
const index = this.children.indexOf(currentChild)
|
||||
return this.addChild(newChild, index + 1)
|
||||
}
|
||||
|
||||
reparentLastChild () {
|
||||
const lastChild = this.children[0]
|
||||
lastChild.setFlexScale(this.flexScale)
|
||||
this.parent.replaceChild(this, lastChild)
|
||||
this.destroy()
|
||||
}
|
||||
|
||||
subscribeToChild (child) {
|
||||
const subscription = child.onDidDestroy(() => this.removeChild(child))
|
||||
this.subscriptionsByChild.set(child, subscription)
|
||||
this.subscriptions.add(subscription)
|
||||
}
|
||||
|
||||
unsubscribeFromChild (child) {
|
||||
const subscription = this.subscriptionsByChild.get(child)
|
||||
this.subscriptions.remove(subscription)
|
||||
subscription.dispose()
|
||||
}
|
||||
|
||||
destroyed () {
|
||||
this.subscriptions.dispose()
|
||||
this.emitter.emit('did-destroy')
|
||||
this.emitter.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PaneAxis
|
||||
Reference in New Issue
Block a user