This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#330) tooling: added developer tools API
- Loading branch information
Jonas Schulte
committed
Aug 17, 2016
1 parent
43f59b8
commit 184c602
Showing
4 changed files
with
345 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright 2016 aixigo AG | ||
* Released under the MIT license. | ||
* http://laxarjs.org/license | ||
*/ | ||
define( [ | ||
'angular', | ||
'./pages', | ||
'../logging/log', | ||
'../utilities/object', | ||
'../utilities/configuration' | ||
], | ||
function( ng, pages, log, object, configuration ) { | ||
'use strict'; | ||
|
||
/** | ||
* If the documentElement has the attribute 'data-laxar-developer-tools-extension' or | ||
* the property 'laxarDeveloperToolsExtensionLoaded' of the window is true or | ||
* the tooling is enabled by configuration in the laxar application then | ||
* laxar is providing the API by creating the object `window.laxarDeveloperToolsApi`. | ||
* The attribute 'data-laxar-developer-tools-extension' is set by the web extension and | ||
* the property 'laxarDeveloperToolsExtensionLoaded' is set by the firefox extension. | ||
*/ | ||
function create( eventBus ) { | ||
if( !( window.laxarDeveloperToolsExtensionLoaded || | ||
document.documentElement.hasAttribute( 'data-laxar-developer-tools-extension' ) || | ||
configuration.get( 'tooling.enabled', false ) ) ) { | ||
return; | ||
} | ||
|
||
pages.addListener( onPageChange ); | ||
var bufferSize = configuration.get( 'tooling.bufferSize', 2500 ); | ||
|
||
var developerHooks = window.laxarDeveloperToolsApi = ( window.laxarDeveloperToolsApi || {} ); | ||
developerHooks.buffers = { events: [], log: [] } ; | ||
developerHooks.eventCounter = Date.now(); | ||
developerHooks.logCounter = Date.now(); | ||
developerHooks.pageInfo = pages.current(); | ||
developerHooks.pageInfoVersion = 1; | ||
developerHooks.gridSettings = configuration.get( 'tooling.grid', null ); | ||
|
||
log.addLogChannel( logChannel ); | ||
var cleanupInspector = eventBus.addInspector( inspector ); | ||
|
||
window.addEventListener( 'beforeunload', function() { | ||
log.removeLogChannel( logChannel ); | ||
cleanupInspector(); | ||
} ); | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
function logChannel( messageObject ) { | ||
var index = developerHooks.logCounter++; | ||
var jsonItem = JSON.stringify( messageObject ); | ||
pushIntoStore( 'log', { index: index, json: jsonItem } ); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
function inspector( item ) { | ||
var index = developerHooks.eventCounter++; | ||
var jsonItem = JSON.stringify( object.options( { time: Date.now() }, item ) ); | ||
pushIntoStore( 'events', { index: index, json: jsonItem } ); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
function onPageChange( pageInfo ) { | ||
developerHooks.pageInfo = pageInfo; | ||
++developerHooks.pageInfoVersion; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
function pushIntoStore( storeName, item ) { | ||
var buffer = developerHooks.buffers[ storeName ]; | ||
while( buffer.length >= bufferSize ) { | ||
buffer.shift(); | ||
} | ||
buffer.push( item ); | ||
} | ||
} | ||
|
||
return ng.module( 'axToolingExternalApi', [] ).run( [ 'axGlobalEventBus', create ] ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters