Skip to content

Commit 5c4a98d

Browse files
committed
named export
views in ui already fixed in the other PR
1 parent f4f30de commit 5c4a98d

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

lib/ui/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { CompositeDisposable } from 'atom'
44
import { client } from '../connection'
5-
const views = require('./views')
5+
import * as views from './views'
66
import goto from '../runtime/goto'
77

88
const {

lib/ui/views.js

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { once } from '../misc';
55

66
const getlazy = client.import('getlazy');
77

8-
let views;
9-
export default views = {
10-
dom({tag, attrs, contents}, opts) {
8+
9+
export function dom({tag, attrs, contents}, opts) {
1110
const view = document.createElement(tag);
1211
for (let k in attrs) {
1312
let v = attrs[k];
@@ -19,65 +18,65 @@ export default views = {
1918
contents = [contents];
2019
}
2120
for (let child of contents) {
22-
view.appendChild(this.render(child, opts));
21+
view.appendChild(render(child, opts));
2322
}
2423
}
2524
return view;
26-
},
25+
}
2726

28-
html(...args) {
27+
export function html(...args) {
2928
const obj = args[0],
3029
{
3130
content
3231
} = obj,
3332
val = obj.block,
3433
block = val != null ? val : false;
35-
let view = this.render(block ? this.tags.div() : this.tags.span());
34+
let view = render(block ? tags.div() : tags.span());
3635
view.innerHTML = content;
3736
return view = view.children.length === 1 ? view.children[0] : view;
38-
},
37+
}
3938

40-
tree({head, children, expand}, opts) {
41-
this.ink.tree.treeView(this.render(head, opts),
42-
children.map(x=> this.render(this.tags.div([x]), opts)),
39+
export function tree({head, children, expand}, opts) {
40+
this.ink.tree.treeView(render(head, opts),
41+
children.map(x=> render(tags.div([x]), opts)),
4342
{expand});
44-
},
43+
}
4544

46-
lazy({head, id}, opts) {
45+
export function lazy({head, id}, opts) {
4746
const conn = client.conn;
4847
if (opts.registerLazy != null) {
4948
opts.registerLazy(id);
5049
} else {
5150
console.warn('Unregistered lazy view');
5251
}
5352
let view;
54-
return view = this.ink.tree.treeView(this.render(head, opts), [], {
53+
return view = this.ink.tree.treeView(render(head, opts), [], {
5554
onToggle: once(() => {
5655
if (client.conn !== conn) { return; }
5756
getlazy(id).then(children => {
5857
const body = view.querySelector(':scope > .body');
59-
children.map(x => this.render(this.tags.div([x]), opts)).forEach(x => {
58+
children.map(x => render(tags.div([x]), opts)).forEach(x => {
6059
body.appendChild(this.ink.ansiToHTML(x));
6160
});
6261
});
6362
})
6463
}
6564
);
66-
},
65+
}
6766

68-
subtree({label, child}, opts) {
69-
return this.render((child.type === "tree" ?{
67+
export function subtree({label, child}, opts) {
68+
return render((child.type === "tree" ?{
7069
type: "tree",
71-
head: this.tags.span([label, child.head]),
70+
head: tags.span([label, child.head]),
7271
children: child.children
7372
}
7473
// children: child.children.map((x) => @tags.span "gutted", x)
7574
:
76-
this.tags.span("gutted", [label, child])), opts);
77-
},
75+
tags.span("gutted", [label, child])), opts);
76+
}
7877

79-
copy({view, text}, opts) {
80-
view = this.render(view, opts);
78+
export function copy({view, text}, opts) {
79+
view = render(view, opts);
8180
atom.commands.add(view, {
8281
'core:copy'(e) {
8382
atom.clipboard.write(text);
@@ -86,10 +85,10 @@ export default views = {
8685
}
8786
);
8887
return view;
89-
},
88+
}
9089

91-
link({file, line, contents}) {
92-
const view = this.render(this.tags.a({href: '#'}, contents));
90+
export function link({file, line, contents}) {
91+
const view = render(tags.a({href: '#'}, contents));
9392
// TODO: maybe need to dispose of the tooltip onclick and readd them, but
9493
// that doesn't seem to be necessary
9594
let tt;
@@ -108,61 +107,61 @@ export default views = {
108107
tt.dispose();
109108
});
110109
return view;
111-
},
110+
}
112111

113-
number({value, full}) {
112+
export function number({value, full}) {
114113
let rounded = value.toPrecision(3);
115114
if (rounded.toString().length < full.length) { rounded += '…'; }
116-
const view = this.render(this.tags.span('syntax--constant syntax--numeric', rounded));
115+
const view = render(tags.span('syntax--constant syntax--numeric', rounded));
117116
let isfull = false;
118117
view.onclick = function(e) {
119118
view.innerText = !isfull ? full : rounded;
120119
isfull = !isfull;
121120
e.stopPropagation();
122121
};
123122
return view;
124-
},
123+
}
125124

126-
code({text, attrs, scope}) {
125+
export function code({text, attrs, scope}) {
127126
const grammar = atom.grammars.grammarForScopeName("source.julia");
128127
const block = (attrs != null ? attrs.block : undefined) || false; // attrs?.block || false
129128
const highlighted = Highlighter.highlight(text, grammar, {scopePrefix: 'syntax--', block});
130-
return this.render({type: 'html', block, content: highlighted});
131-
},
129+
return render({type: 'html', block, content: highlighted});
130+
}
132131

133-
latex({attrs, text}) {
132+
export function latex({attrs, text}) {
134133
const block = (attrs != null ? attrs.block : undefined) || false; // attrs?.block || false
135134
const latex = this.ink.KaTeX.texify(text, block);
136-
return this.render({type: 'html', block, content: latex});
137-
},
135+
return render({type: 'html', block, content: latex});
136+
}
138137

139-
views: {
138+
export const views = {
140139
// TODO Remove unnecessary use of Array.from
141-
dom(...a) { return views.dom(...a); },
142-
html(...a) { return views.html(...a); },
143-
tree(...a) { return views.tree(...a); },
144-
lazy(...a) { return views.lazy(...a); },
145-
subtree(...a) { return views.subtree(...a); },
146-
link(...a) { return views.link(...a); },
147-
copy(...a) { return views.copy(...a); },
148-
number(...a) { return views.number(...a); },
149-
code(...a) { return views.code(...a); },
150-
latex(...a) { return views.latex(...a); }
151-
},
152-
153-
render(data, opts = {}) {
154-
if (this.views.hasOwnProperty(data.type)) {
155-
const r = this.views[data.type](data, opts);
140+
dom(...a) { return dom(...a); },
141+
html(...a) { return html(...a); },
142+
tree(...a) { return tree(...a); },
143+
lazy(...a) { return lazy(...a); },
144+
subtree(...a) { return subtree(...a); },
145+
link(...a) { return link(...a); },
146+
copy(...a) { return copy(...a); },
147+
number(...a) { return number(...a); },
148+
code(...a) { return code(...a); },
149+
latex(...a) { return latex(...a); }
150+
}
151+
152+
export function render(data, opts = {}) {
153+
if (views.hasOwnProperty(data.type)) {
154+
const r = views[data.type](data, opts);
156155
this.ink.ansiToHTML(r);
157156
return r;
158157
} else if ((data != null ? data.constructor : undefined) === String) { // data?.constructor === String
159158
return new Text(data);
160159
} else {
161-
return this.render(`julia-client: can't render ${(data != null ? data.type : undefined)}`); // data?.type
160+
return render(`julia-client: can't render ${(data != null ? data.type : undefined)}`); // data?.type
162161
}
163-
},
162+
}
164163

165-
tag(tag, attrs, contents) {
164+
export function tag(tag, attrs, contents) {
166165
if ((attrs != null ? attrs.constructor : undefined) === String) { // attrs?.constructor === String
167166
attrs = {class: attrs};
168167
}
@@ -175,9 +174,10 @@ export default views = {
175174
attrs,
176175
contents
177176
};
178-
},
179-
180-
tags: {}
181-
};
177+
}
182178

183-
['div', 'span', 'a', 'strong', 'table', 'tr', 'td', 'webview'].forEach(tag => views.tags[tag] = (attrs, contents) => views.tag(tag, attrs, contents));
179+
export let tags = {}
180+
const tags_arr = ['div', 'span', 'a', 'strong', 'table', 'tr', 'td', 'webview']
181+
for (let _tag of tags_arr) {
182+
tags[_tag] = (attrs, contents) => tag(_tag, attrs, contents)
183+
}

0 commit comments

Comments
 (0)