Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ exports.middleware = store => next => action => {
const {type, data} = action
const {sessions} = store.getState()
const {activeUid} = sessions
// Remove ANSI escape code sequences. Visualization: https://goo.gl/IY8vuU
const ANSI_escape_codes = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/gm
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants won't change, so they shouldn't be defined inside the middleware.

Copy link
Author

@stereokai stereokai Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I'll update.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Match hyperlayout config string and ignore lints. Visualization: https://goo.gl/hxz4S1
const config_matcher = /(?:.|\s)*\[hyperlayout config\]:((?:.|\s)*})(?:.|\s)*/gm
// Cross-os new-line characters. Visualization: https://goo.gl/q501uy
const newlines = /[\n\r]/gm

// Check for hyperlayout config
if (type === 'SESSION_ADD_DATA') {
const testedData = /^\[hyperlayout config]:(.*)/.exec(data)
data = data.replace(ANSI_escape_codes, '')
const testedData = config_matcher.exec(data.trim());
if (testedData && testedData[1]) {
const config = JSON.parse(testedData[1])
const config = JSON.parse(testedData[1].replace(newlines, ''))
hyperlayout = new Hyperlayout(config, store)
return
}
Expand Down