Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17938 from atom/mb-decaf-classes-with-deserializers
Browse files Browse the repository at this point in the history
Fix classes whose constructor name was broken by minification
  • Loading branch information
Max Brunsfeld committed Aug 28, 2018
2 parents b07c080 + d0e5858 commit f3ca547
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 151 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
147 changes: 0 additions & 147 deletions src/pane-axis.coffee

This file was deleted.

199 changes: 199 additions & 0 deletions src/pane-axis.js
@@ -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

0 comments on commit f3ca547

Please sign in to comment.