Skip to content

Commit ffef757

Browse files
committed
feat: Store settings at URL, close #2
1 parent 99b0673 commit ffef757

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# jsoncompare.com [![Build Status](https://travis-ci.org/circlecell/jsoncompare.com.svg?branch=master)](https://travis-ci.org/circlecell/jsoncompare.com)
22

3-
Source code for http://jsoncompare.com
3+
Source code for [jsoncompare.com](jsoncompare.com).
44

55
## API
66
``POST https://jsoncompare.com/api/save`` - saves current application state on S3.

packages/frontend/js/main/index.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,55 @@ import { dataset } from 'matreshka/binders';
33
import initRouter from 'matreshka-router';
44
import beautify from 'js-beautify/js/lib/beautify';
55
import minify from 'jsonminify';
6+
import qs from 'qs';
67
import LintEditor from '../linteditor';
78
import Sandbox from './components/sandbox';
89
import Tabs from './tabs';
910

10-
1111
export default class Main extends Matreshka {
1212
constructor() {
13-
initRouter(super(), 'mode/id')
13+
initRouter(super(), 'mode/params')
1414
.instantiate('tabs', Tabs)
1515
.set({
1616
memo: {},
1717
mode: this.mode || 'simple',
1818
defaultView: this.toJSONString(),
1919
saved: true,
20-
loading: true,
21-
fullscreen: false
20+
loading: true
21+
})
22+
.calc({
23+
id: {
24+
source: 'params',
25+
handler: params => (qs.parse(params).id || null)
26+
},
27+
fullscreen: {
28+
source: 'params',
29+
handler: params => 'fullscreen' in qs.parse(params)
30+
},
31+
reformat: {
32+
source: 'params',
33+
handler: params => (qs.parse(params).reformat || null)
34+
},
35+
params: {
36+
source: ['id', 'fullscreen', 'reformat'],
37+
handler(id, fullscreen, reformat) {
38+
const params = [];
39+
40+
if (id) {
41+
params.push(`id=${id}`);
42+
}
43+
44+
if (fullscreen) {
45+
params.push('fullscreen');
46+
}
47+
48+
if (reformat) {
49+
params.push(`reformat=${reformat}`);
50+
}
51+
52+
return params.join('&');
53+
}
54+
}
2255
})
2356
.bindSandbox(<Sandbox owner={this} />)
2457
.bindNode('win', window)

packages/frontend/js/realdom/createelement.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ module.exports = function createElement(givenElement, attributes, ...children) {
1111
element = givenElement;
1212
}
1313

14+
for (let i = 0; i < children.length; i++) {
15+
let child = children[i];
16+
17+
if (typeof child === 'string') {
18+
child = document.createTextNode(child);
19+
}
20+
21+
if (child instanceof Node) {
22+
element.appendChild(child);
23+
}
24+
}
25+
1426
if (attributes) {
1527
for (let i = 0, keys = Object.keys(attributes); i < keys.length; i++) {
1628
const name = keys[i];
@@ -25,25 +37,11 @@ module.exports = function createElement(givenElement, attributes, ...children) {
2537
&& lowerCasedName in element
2638
) {
2739
element[lowerCasedName] = value;
28-
} else {
40+
} else if (name !== 'owner') {
2941
element.setAttribute(name, value);
3042
}
3143
}
3244
}
3345

34-
for (let i = 0; i < children.length; i++) {
35-
let child = children[i];
36-
37-
if (typeof child === 'string') {
38-
child = document.createTextNode(child);
39-
}
40-
41-
if (!(child instanceof Node)) {
42-
throw Error(`RealDOM JSX can not contain ${typeof child}`);
43-
}
44-
45-
element.appendChild(child);
46-
}
47-
4846
return element;
4947
};

packages/frontend/package-lock.json

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

packages/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"matreshka-binders-file": "0.0.2",
2929
"matreshka-router": "1.0.30",
3030
"object.assign": "^4.0.4",
31+
"qs": "^6.4.0",
3132
"valid-url": "^1.0.9"
3233
},
3334
"devDependencies": {

0 commit comments

Comments
 (0)