Skip to content

Commit 057f34e

Browse files
author
Matt Godbolt
committed
Merge branch 'noah79-master'
2 parents 90ad2b8 + 46ffa31 commit 057f34e

4 files changed

Lines changed: 75 additions & 35 deletions

File tree

dist/goldenlayout.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,23 @@ lm.utils.EventEmitter = function() {
246246

247247
args = Array.prototype.slice.call( arguments, 1 );
248248

249-
if( this._mSubscriptions[ sEvent ] ) {
250-
for( i = 0; i < this._mSubscriptions[ sEvent ].length; i++ ) {
251-
ctx = this._mSubscriptions[ sEvent ][ i ].ctx || {};
252-
this._mSubscriptions[ sEvent ][ i ].fn.apply( ctx, args );
249+
var subs = this._mSubscriptions[ sEvent ];
250+
251+
if( subs ) {
252+
subs = subs.slice();
253+
for( i = 0; i < subs.length; i++ ) {
254+
ctx = subs[ i ].ctx || {};
255+
subs[ i ].fn.apply( ctx, args );
253256
}
254257
}
255258

256259
args.unshift( sEvent );
257260

258-
for( i = 0; i < this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ].length; i++ ) {
259-
ctx = this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ][ i ].ctx || {};
260-
this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ][ i ].fn.apply( ctx, args );
261+
var allEventSubs = this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ].slice()
262+
263+
for( i = 0; i <allEventSubs.length; i++ ) {
264+
ctx = allEventSubs[ i ].ctx || {};
265+
allEventSubs[ i ].fn.apply( ctx, args );
261266
}
262267
};
263268

dist/goldenlayout.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// Project: https://golden-layout.com/
33

44
declare module 'golden-layout' {
5-
6-
class GoldenLayout {
5+
class GoldenLayout implements GoldenLayout.EventEmitter {
76
/**
87
* The topmost item in the layout item tree. In browser terms: Think of the GoldenLayout instance as window
98
* object and of goldenLayout.root as the document.
@@ -62,7 +61,7 @@ declare module 'golden-layout' {
6261
* @param config A GoldenLayout configuration object
6362
* @param container The DOM element the layout will be initialised in. Default: document.body
6463
*/
65-
constructor(configuration: GoldenLayout.Config, container?: HTMLElement | JQuery);
64+
constructor(configuration: GoldenLayout.Config, container?: Element | HTMLElement | JQuery);
6665

6766
/*
6867
* @param name The name of the component, as referred to by componentName in the component configuration.
@@ -110,7 +109,6 @@ declare module 'golden-layout' {
110109
*/
111110
createContentItem(itemConfiguration?: GoldenLayout.ItemConfigType, parent?: GoldenLayout.ContentItem): void;
112111

113-
114112
/**
115113
* Creates a new popout window with configOrContentItem as contents at the position specified in dimensions
116114
* @param configOrContentItem The content item or config that will be created in the new window. If a item is
@@ -123,13 +121,13 @@ declare module 'golden-layout' {
123121
* @param indexInParent The index at which the child window's contents will be appended to. Default: null
124122
*/
125123
createPopout(configOrContentItem: GoldenLayout.ItemConfigType | GoldenLayout.ContentItem,
126-
dimensions: {
127-
width: number,
128-
height: number,
129-
left: number,
130-
top: number
131-
}, parentId?: string,
132-
indexInParent?: number): void;
124+
dimensions: {
125+
width: number,
126+
height: number,
127+
left: number,
128+
top: number
129+
}, parentId?: string,
130+
indexInParent?: number): void;
133131

134132
/**
135133
* Turns a DOM element into a dragSource, meaning that the user can drag the element directly onto the layout
@@ -157,6 +155,40 @@ declare module 'golden-layout' {
157155
* @param minifiedConfig A minified GoldenLayout configuration object
158156
*/
159157
static unminifyConfig(minifiedConfig: any): any;
158+
159+
/**
160+
* Subscribe to an event
161+
* @param eventName The name of the event to describe to
162+
* @param callback The function that should be invoked when the event occurs
163+
* @param context The value of the this pointer in the callback function
164+
*/
165+
on(eventName: string, callback: Function, context?: any): void;
166+
167+
/**
168+
* Notify listeners of an event and pass arguments along
169+
* @param eventName The name of the event to emit
170+
*/
171+
emit(eventName: string, arg1?: any, arg2?: any, ...argN: any[]): void;
172+
173+
/**
174+
* Alias for emit
175+
*/
176+
trigger(eventName: string, arg1?: any, arg2?: any, ...argN: any[]): void;
177+
178+
/**
179+
* Unsubscribes either all listeners if just an eventName is provided, just a specific callback if invoked with
180+
* eventName and callback or just a specific callback with a specific context if invoked with all three
181+
* arguments.
182+
* @param eventName The name of the event to unsubscribe from
183+
* @param callback The function that should be invoked when the event occurs
184+
* @param context The value of the this pointer in the callback function
185+
*/
186+
unbind(eventName: string, callback?: Function, context?: any): void;
187+
188+
/**
189+
* Alias for unbind
190+
*/
191+
off(eventName: string, callback?: Function, context?: any): void;
160192
}
161193

162194
namespace GoldenLayout {
@@ -222,13 +254,13 @@ declare module 'golden-layout' {
222254
* Specifies if the maximise icon should be displayed in the header-bar.
223255
* Default: true
224256
*/
225-
showMaximiseIcon: boolean;
257+
showMaximiseIcon?: boolean;
226258

227259
/**
228260
* Specifies if the close icon should be displayed in the header-bar.
229261
* Default: true
230262
*/
231-
showCloseIcon: boolean;
263+
showCloseIcon?: boolean;
232264
}
233265

234266
export interface Dimensions {
@@ -366,7 +398,7 @@ declare module 'golden-layout' {
366398
settings?: Settings;
367399
dimensions?: Dimensions;
368400
labels?: Labels;
369-
content: ItemConfigType[];
401+
content?: ItemConfigType[];
370402
}
371403

372404
export interface ContentItem extends EventEmitter {
@@ -462,7 +494,7 @@ declare module 'golden-layout' {
462494

463495
/**
464496
* The contentItem that should be removed
465-
* @param oldChild ContentItem The contentItem that should be removed
497+
* @param oldChild ContentItem The contentItem that should be removed
466498
* @param newChild A content item (or tree of content items) or an ItemConfiguration to create the item from
467499
*/
468500
replaceChild(oldChild: ContentItem, newChild: ContentItem | ItemConfigType): void;
@@ -631,7 +663,7 @@ declare module 'golden-layout' {
631663
getState(): any;
632664

633665
/**
634-
* Returns the container's inner element as a jQuery element
666+
* Returns the container's inner element as a jQuery element
635667
*/
636668
getElement(): JQuery;
637669

@@ -718,7 +750,6 @@ declare module 'golden-layout' {
718750
*/
719751
parent: ContentItem;
720752

721-
722753
/**
723754
* An array of the Tabs within this header
724755
*/
@@ -847,5 +878,4 @@ declare module 'golden-layout' {
847878
}
848879

849880
export = GoldenLayout;
850-
851881
}

src/js/utils/EventEmitter.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,23 @@ lm.utils.EventEmitter = function() {
4848

4949
args = Array.prototype.slice.call( arguments, 1 );
5050

51-
if( this._mSubscriptions[ sEvent ] ) {
52-
for( i = 0; i < this._mSubscriptions[ sEvent ].length; i++ ) {
53-
ctx = this._mSubscriptions[ sEvent ][ i ].ctx || {};
54-
this._mSubscriptions[ sEvent ][ i ].fn.apply( ctx, args );
51+
var subs = this._mSubscriptions[ sEvent ];
52+
53+
if( subs ) {
54+
subs = subs.slice();
55+
for( i = 0; i < subs.length; i++ ) {
56+
ctx = subs[ i ].ctx || {};
57+
subs[ i ].fn.apply( ctx, args );
5558
}
5659
}
5760

5861
args.unshift( sEvent );
5962

60-
for( i = 0; i < this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ].length; i++ ) {
61-
ctx = this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ][ i ].ctx || {};
62-
this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ][ i ].fn.apply( ctx, args );
63+
var allEventSubs = this._mSubscriptions[ lm.utils.EventEmitter.ALL_EVENT ].slice()
64+
65+
for( i = 0; i <allEventSubs.length; i++ ) {
66+
ctx = allEventSubs[ i ].ctx || {};
67+
allEventSubs[ i ].fn.apply( ctx, args );
6368
}
6469
};
6570

0 commit comments

Comments
 (0)