explicit snip loadedness tracking

This commit is contained in:
Anton Dyudin 2015-07-22 17:14:56 -07:00
parent c0f82f42e6
commit 8769418ef4
4 changed files with 34 additions and 35 deletions

View File

@ -77,11 +77,9 @@ module.exports = recl
up = @state.pare ? "/"
if up.slice(-1) is "/" then up = up.slice 0,-1
unless @state.cont[up]?
TreeActions.getPath up
unless @state.cont[up]? then TreeActions.getPath up
unless (_(@state.sibs).keys().every (k) => @state.snip[up+"/"+k]?)
TreeActions.getPath up, "snip"
unless TreeStore.gotSnip(up) then TreeActions.getPath up, "snip"
componentDidUpdate: ->
@setTitle()
@ -119,6 +117,8 @@ module.exports = recl
href = window.tree.basepath path
(a {href,key:"arow-#{name}",className:"arow-#{name}"},"")
toText: (elem)-> $(React.renderToStaticMarkup elem).text()
renderParts: -> [
if @state.pare then _.filter [
div {id:"up",key:"up"}, @renderArrow "up", @state.pare
@ -141,9 +141,9 @@ module.exports = recl
path = up+"/"+i
href = window.tree.basepath path
snip = @state.snip[path]
head = snip?.meta?.title ? snip?.head ? i
if typeof head isnt 'string'
head = $(React.renderToStaticMarkup head).text()
head = snip?.meta?.title
head ?= @toText snip?.head if snip?.head
head ||= i
(div {className,key:i}, (a {href,onClick:@_click}, head))
style = {marginTop:"#{-24*ci}px"}
div {key:"sibs",id:"sibs",style}, _sibs

View File

@ -26,10 +26,7 @@ module.exports = recl
getInitialState: -> @stateFromStore()
gotPath: ->
_keys = _(@state.tree).keys()
(not _keys.isEmpty()) and _keys.every (k) =>
@state.snip[@state.path+"/"+k]?
gotPath: -> TreeStore.gotSnip(@state.path)
componentDidMount: ->
TreeStore.addChangeListener @_onChangeStore

View File

@ -161,11 +161,7 @@ module.exports = recl({
if (this.state.cont[up] == null) {
TreeActions.getPath(up);
}
if (!(_(this.state.sibs).keys().every((function(_this) {
return function(k) {
return _this.state.snip[up + "/" + k] != null;
};
})(this)))) {
if (!TreeStore.gotSnip(up)) {
return TreeActions.getPath(up, "snip");
}
},
@ -219,6 +215,9 @@ module.exports = recl({
className: "arow-" + name
}, "");
},
toText: function(elem) {
return $(React.renderToStaticMarkup(elem)).text();
},
renderParts: function() {
var _sibs, ci, curr, j, k, ref1, style, up;
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
]) : 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) {
var className, head, href, path, ref2, ref3, ref4, snip;
var className, head, href, path, ref2, snip;
if (curr === i) {
className = "active";
ci = k;
@ -244,10 +243,13 @@ module.exports = recl({
path = up + "/" + i;
href = window.tree.basepath(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;
if (typeof head !== 'string') {
head = $(React.renderToStaticMarkup(head)).text();
head = snip != null ? (ref2 = snip.meta) != null ? ref2.title : void 0 : void 0;
if (snip != null ? snip.head : void 0) {
if (head == null) {
head = _this.toText(snip != null ? snip.head : void 0);
}
}
head || (head = i);
return div({
className: className,
key: i
@ -473,13 +475,7 @@ module.exports = recl({
return this.stateFromStore();
},
gotPath: function() {
var _keys;
_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));
return TreeStore.gotSnip(this.state.path);
},
componentDidMount: function() {
TreeStore.addChangeListener(this._onChangeStore);
@ -1160,7 +1156,7 @@ 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;
@ -1174,6 +1170,8 @@ _cont = {};
_snip = {};
_got_snip = {};
_curr = "";
TreeStore = _.extend(EventEmitter.prototype, {
@ -1228,23 +1226,24 @@ TreeStore = _.extend(EventEmitter.prototype, {
getSnip: function() {
return _snip;
},
gotSnip: function(path) {
return !!_got_snip[path];
},
loadSnip: function(path, snip) {
var k, results, v;
var k, v;
this.mergePathToTree(path, _.pluck(snip, "name"));
if ((snip != null ? snip.length : void 0) !== 0) {
results = [];
for (k in snip) {
v = snip[k];
results.push(_snip[path + "/" + v.name] = {
_snip[path + "/" + v.name] = {
head: window.tree.reactify(v.body.head),
body: window.tree.reactify(v.body.body),
orig: v.body,
meta: v.meta
});
};
}
return results;
} else {
return _cont[path] = window.tree.reactify({
_cont[path] = window.tree.reactify({
gn: 'div',
c: [
{
@ -1268,6 +1267,7 @@ TreeStore = _.extend(EventEmitter.prototype, {
]
});
}
return _got_snip[path] = true;
},
loadKids: function(path, kids) {
var k, results, v;

View File

@ -5,7 +5,7 @@ clog = console.log
_tree = {}
_cont = {}
_snip = {}
_snip = {}; _got_snip = {}
_curr = ""
TreeStore = _.extend EventEmitter.prototype, {
@ -40,6 +40,7 @@ TreeStore = _.extend EventEmitter.prototype, {
tree
getSnip: -> _snip
gotSnip: (path)-> !!_got_snip[path]
loadSnip: (path,snip) ->
@mergePathToTree path,_.pluck(snip,"name")
@ -58,6 +59,7 @@ TreeStore = _.extend EventEmitter.prototype, {
{gn:'pre', c:[@getCurr()]}
{gn:'span', c:['is either empty or does not exist.']}
] }]
_got_snip[path] = true
loadKids: (path,kids) ->
@mergePathToTree path,_.pluck(kids,"name")