mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 18:12:47 +03:00
explicit snip loadedness tracking
This commit is contained in:
parent
c0f82f42e6
commit
8769418ef4
@ -77,11 +77,9 @@ module.exports = recl
|
|||||||
up = @state.pare ? "/"
|
up = @state.pare ? "/"
|
||||||
if up.slice(-1) is "/" then up = up.slice 0,-1
|
if up.slice(-1) is "/" then up = up.slice 0,-1
|
||||||
|
|
||||||
unless @state.cont[up]?
|
unless @state.cont[up]? then TreeActions.getPath up
|
||||||
TreeActions.getPath up
|
|
||||||
|
|
||||||
unless (_(@state.sibs).keys().every (k) => @state.snip[up+"/"+k]?)
|
unless TreeStore.gotSnip(up) then TreeActions.getPath up, "snip"
|
||||||
TreeActions.getPath up, "snip"
|
|
||||||
|
|
||||||
componentDidUpdate: ->
|
componentDidUpdate: ->
|
||||||
@setTitle()
|
@setTitle()
|
||||||
@ -119,6 +117,8 @@ module.exports = recl
|
|||||||
href = window.tree.basepath path
|
href = window.tree.basepath path
|
||||||
(a {href,key:"arow-#{name}",className:"arow-#{name}"},"")
|
(a {href,key:"arow-#{name}",className:"arow-#{name}"},"")
|
||||||
|
|
||||||
|
toText: (elem)-> $(React.renderToStaticMarkup elem).text()
|
||||||
|
|
||||||
renderParts: -> [
|
renderParts: -> [
|
||||||
if @state.pare then _.filter [
|
if @state.pare then _.filter [
|
||||||
div {id:"up",key:"up"}, @renderArrow "up", @state.pare
|
div {id:"up",key:"up"}, @renderArrow "up", @state.pare
|
||||||
@ -141,9 +141,9 @@ module.exports = recl
|
|||||||
path = up+"/"+i
|
path = up+"/"+i
|
||||||
href = window.tree.basepath path
|
href = window.tree.basepath path
|
||||||
snip = @state.snip[path]
|
snip = @state.snip[path]
|
||||||
head = snip?.meta?.title ? snip?.head ? i
|
head = snip?.meta?.title
|
||||||
if typeof head isnt 'string'
|
head ?= @toText snip?.head if snip?.head
|
||||||
head = $(React.renderToStaticMarkup head).text()
|
head ||= i
|
||||||
(div {className,key:i}, (a {href,onClick:@_click}, head))
|
(div {className,key:i}, (a {href,onClick:@_click}, head))
|
||||||
style = {marginTop:"#{-24*ci}px"}
|
style = {marginTop:"#{-24*ci}px"}
|
||||||
div {key:"sibs",id:"sibs",style}, _sibs
|
div {key:"sibs",id:"sibs",style}, _sibs
|
||||||
|
@ -26,10 +26,7 @@ module.exports = recl
|
|||||||
|
|
||||||
getInitialState: -> @stateFromStore()
|
getInitialState: -> @stateFromStore()
|
||||||
|
|
||||||
gotPath: ->
|
gotPath: -> TreeStore.gotSnip(@state.path)
|
||||||
_keys = _(@state.tree).keys()
|
|
||||||
(not _keys.isEmpty()) and _keys.every (k) =>
|
|
||||||
@state.snip[@state.path+"/"+k]?
|
|
||||||
|
|
||||||
componentDidMount: ->
|
componentDidMount: ->
|
||||||
TreeStore.addChangeListener @_onChangeStore
|
TreeStore.addChangeListener @_onChangeStore
|
||||||
|
@ -161,11 +161,7 @@ module.exports = recl({
|
|||||||
if (this.state.cont[up] == null) {
|
if (this.state.cont[up] == null) {
|
||||||
TreeActions.getPath(up);
|
TreeActions.getPath(up);
|
||||||
}
|
}
|
||||||
if (!(_(this.state.sibs).keys().every((function(_this) {
|
if (!TreeStore.gotSnip(up)) {
|
||||||
return function(k) {
|
|
||||||
return _this.state.snip[up + "/" + k] != null;
|
|
||||||
};
|
|
||||||
})(this)))) {
|
|
||||||
return TreeActions.getPath(up, "snip");
|
return TreeActions.getPath(up, "snip");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -219,6 +215,9 @@ module.exports = recl({
|
|||||||
className: "arow-" + name
|
className: "arow-" + name
|
||||||
}, "");
|
}, "");
|
||||||
},
|
},
|
||||||
|
toText: function(elem) {
|
||||||
|
return $(React.renderToStaticMarkup(elem)).text();
|
||||||
|
},
|
||||||
renderParts: function() {
|
renderParts: function() {
|
||||||
var _sibs, ci, curr, j, k, ref1, style, up;
|
var _sibs, ci, curr, j, k, ref1, style, up;
|
||||||
return [
|
return [
|
||||||
@ -232,7 +231,7 @@ module.exports = recl({
|
|||||||
}, _.filter([this.state.prev ? this.renderArrow("prev", this.state.prev) : void 0, this.state.next ? this.renderArrow("next", this.state.next) : void 0])) : void 0
|
}, _.filter([this.state.prev ? this.renderArrow("prev", this.state.prev) : void 0, this.state.next ? this.renderArrow("next", this.state.next) : void 0])) : void 0
|
||||||
]) : void 0, _.keys(this.state.sibs).length > 0 ? ((ref1 = this.state.path.split("/"), up = 2 <= ref1.length ? slice.call(ref1, 0, j = ref1.length - 1) : (j = 0, []), curr = ref1[j++], ref1), up = up.join("/"), ci = 0, k = 0, _sibs = _(this.state.sibs).keys().sort().map((function(_this) {
|
]) : void 0, _.keys(this.state.sibs).length > 0 ? ((ref1 = this.state.path.split("/"), up = 2 <= ref1.length ? slice.call(ref1, 0, j = ref1.length - 1) : (j = 0, []), curr = ref1[j++], ref1), up = up.join("/"), ci = 0, k = 0, _sibs = _(this.state.sibs).keys().sort().map((function(_this) {
|
||||||
return function(i) {
|
return function(i) {
|
||||||
var className, head, href, path, ref2, ref3, ref4, snip;
|
var className, head, href, path, ref2, snip;
|
||||||
if (curr === i) {
|
if (curr === i) {
|
||||||
className = "active";
|
className = "active";
|
||||||
ci = k;
|
ci = k;
|
||||||
@ -244,10 +243,13 @@ module.exports = recl({
|
|||||||
path = up + "/" + i;
|
path = up + "/" + i;
|
||||||
href = window.tree.basepath(path);
|
href = window.tree.basepath(path);
|
||||||
snip = _this.state.snip[path];
|
snip = _this.state.snip[path];
|
||||||
head = (ref2 = (ref3 = snip != null ? (ref4 = snip.meta) != null ? ref4.title : void 0 : void 0) != null ? ref3 : snip != null ? snip.head : void 0) != null ? ref2 : i;
|
head = snip != null ? (ref2 = snip.meta) != null ? ref2.title : void 0 : void 0;
|
||||||
if (typeof head !== 'string') {
|
if (snip != null ? snip.head : void 0) {
|
||||||
head = $(React.renderToStaticMarkup(head)).text();
|
if (head == null) {
|
||||||
|
head = _this.toText(snip != null ? snip.head : void 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
head || (head = i);
|
||||||
return div({
|
return div({
|
||||||
className: className,
|
className: className,
|
||||||
key: i
|
key: i
|
||||||
@ -473,13 +475,7 @@ module.exports = recl({
|
|||||||
return this.stateFromStore();
|
return this.stateFromStore();
|
||||||
},
|
},
|
||||||
gotPath: function() {
|
gotPath: function() {
|
||||||
var _keys;
|
return TreeStore.gotSnip(this.state.path);
|
||||||
_keys = _(this.state.tree).keys();
|
|
||||||
return (!_keys.isEmpty()) && _keys.every((function(_this) {
|
|
||||||
return function(k) {
|
|
||||||
return _this.state.snip[_this.state.path + "/" + k] != null;
|
|
||||||
};
|
|
||||||
})(this));
|
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
TreeStore.addChangeListener(this._onChangeStore);
|
TreeStore.addChangeListener(this._onChangeStore);
|
||||||
@ -1160,7 +1156,7 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
},{}],15:[function(require,module,exports){
|
},{}],15:[function(require,module,exports){
|
||||||
var EventEmitter, MessageDispatcher, TreeStore, _cont, _curr, _snip, _tree, clog;
|
var EventEmitter, MessageDispatcher, TreeStore, _cont, _curr, _got_snip, _snip, _tree, clog;
|
||||||
|
|
||||||
EventEmitter = require('events').EventEmitter;
|
EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
@ -1174,6 +1170,8 @@ _cont = {};
|
|||||||
|
|
||||||
_snip = {};
|
_snip = {};
|
||||||
|
|
||||||
|
_got_snip = {};
|
||||||
|
|
||||||
_curr = "";
|
_curr = "";
|
||||||
|
|
||||||
TreeStore = _.extend(EventEmitter.prototype, {
|
TreeStore = _.extend(EventEmitter.prototype, {
|
||||||
@ -1228,23 +1226,24 @@ TreeStore = _.extend(EventEmitter.prototype, {
|
|||||||
getSnip: function() {
|
getSnip: function() {
|
||||||
return _snip;
|
return _snip;
|
||||||
},
|
},
|
||||||
|
gotSnip: function(path) {
|
||||||
|
return !!_got_snip[path];
|
||||||
|
},
|
||||||
loadSnip: function(path, snip) {
|
loadSnip: function(path, snip) {
|
||||||
var k, results, v;
|
var k, v;
|
||||||
this.mergePathToTree(path, _.pluck(snip, "name"));
|
this.mergePathToTree(path, _.pluck(snip, "name"));
|
||||||
if ((snip != null ? snip.length : void 0) !== 0) {
|
if ((snip != null ? snip.length : void 0) !== 0) {
|
||||||
results = [];
|
|
||||||
for (k in snip) {
|
for (k in snip) {
|
||||||
v = snip[k];
|
v = snip[k];
|
||||||
results.push(_snip[path + "/" + v.name] = {
|
_snip[path + "/" + v.name] = {
|
||||||
head: window.tree.reactify(v.body.head),
|
head: window.tree.reactify(v.body.head),
|
||||||
body: window.tree.reactify(v.body.body),
|
body: window.tree.reactify(v.body.body),
|
||||||
orig: v.body,
|
orig: v.body,
|
||||||
meta: v.meta
|
meta: v.meta
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
return results;
|
|
||||||
} else {
|
} else {
|
||||||
return _cont[path] = window.tree.reactify({
|
_cont[path] = window.tree.reactify({
|
||||||
gn: 'div',
|
gn: 'div',
|
||||||
c: [
|
c: [
|
||||||
{
|
{
|
||||||
@ -1268,6 +1267,7 @@ TreeStore = _.extend(EventEmitter.prototype, {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return _got_snip[path] = true;
|
||||||
},
|
},
|
||||||
loadKids: function(path, kids) {
|
loadKids: function(path, kids) {
|
||||||
var k, results, v;
|
var k, results, v;
|
||||||
|
@ -5,7 +5,7 @@ clog = console.log
|
|||||||
|
|
||||||
_tree = {}
|
_tree = {}
|
||||||
_cont = {}
|
_cont = {}
|
||||||
_snip = {}
|
_snip = {}; _got_snip = {}
|
||||||
_curr = ""
|
_curr = ""
|
||||||
|
|
||||||
TreeStore = _.extend EventEmitter.prototype, {
|
TreeStore = _.extend EventEmitter.prototype, {
|
||||||
@ -40,6 +40,7 @@ TreeStore = _.extend EventEmitter.prototype, {
|
|||||||
tree
|
tree
|
||||||
|
|
||||||
getSnip: -> _snip
|
getSnip: -> _snip
|
||||||
|
gotSnip: (path)-> !!_got_snip[path]
|
||||||
|
|
||||||
loadSnip: (path,snip) ->
|
loadSnip: (path,snip) ->
|
||||||
@mergePathToTree path,_.pluck(snip,"name")
|
@mergePathToTree path,_.pluck(snip,"name")
|
||||||
@ -58,6 +59,7 @@ TreeStore = _.extend EventEmitter.prototype, {
|
|||||||
{gn:'pre', c:[@getCurr()]}
|
{gn:'pre', c:[@getCurr()]}
|
||||||
{gn:'span', c:['is either empty or does not exist.']}
|
{gn:'span', c:['is either empty or does not exist.']}
|
||||||
] }]
|
] }]
|
||||||
|
_got_snip[path] = true
|
||||||
|
|
||||||
loadKids: (path,kids) ->
|
loadKids: (path,kids) ->
|
||||||
@mergePathToTree path,_.pluck(kids,"name")
|
@mergePathToTree path,_.pluck(kids,"name")
|
||||||
|
Loading…
Reference in New Issue
Block a user