Kira
4 years ago
40 changed files with 733 additions and 159 deletions
@ -0,0 +1,102 @@
|
||||
(function () { |
||||
var ParentStore = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
context: { |
||||
one: { |
||||
key: "one.key" |
||||
} |
||||
} |
||||
}; |
||||
}, |
||||
childContext: ["context"], |
||||
|
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = { |
||||
two: { |
||||
key: "two.key" |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
BI.model("demo.model.inject.parent_store", ParentStore); |
||||
|
||||
var ChildStore = BI.inherit(Fix.Model, { |
||||
inject: ["context"], |
||||
computed: { |
||||
currContext: function () { |
||||
return this.model.context.one.key; |
||||
} |
||||
}, |
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = { |
||||
one: { |
||||
key: "one.changed_key" |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
BI.model("demo.model.inject.child_store", ChildStore); |
||||
|
||||
var Child = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.inject.child_store"); |
||||
}, |
||||
watch: { |
||||
currContext: function (val) { |
||||
this.button.setText(val); |
||||
} |
||||
}, |
||||
render: function () { |
||||
var self = this; |
||||
return { |
||||
type: "bi.button", |
||||
ref: function () { |
||||
self.button = this; |
||||
}, |
||||
text: this.model.currContext, |
||||
handler: function () { |
||||
self.store.changeContext(); |
||||
} |
||||
}; |
||||
}, |
||||
}); |
||||
|
||||
BI.shortcut("demo.fix_inject_child", Child); |
||||
|
||||
var Parent = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.inject.parent_store"); |
||||
}, |
||||
render: function () { |
||||
var self = this; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
el: { |
||||
type: "demo.fix_inject_child" |
||||
} |
||||
}, { |
||||
el: { |
||||
type: "bi.button", |
||||
text: "点击修改parent state", |
||||
handler: function () { |
||||
self.store.changeContext(); |
||||
} |
||||
} |
||||
}] |
||||
}; |
||||
}, |
||||
mounted: function () { |
||||
|
||||
} |
||||
}); |
||||
|
||||
BI.shortcut("demo.fix_inject", Parent); |
||||
}()); |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,322 @@
|
||||
/** |
||||
* Created by windy on 2018/01/23. |
||||
*/ |
||||
describe("contextTest", function () { |
||||
|
||||
before(function () { |
||||
}); |
||||
|
||||
/** |
||||
* test_author_guy |
||||
*/ |
||||
it("context测试", function () { |
||||
|
||||
var ParentStore = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
context: "默认context" |
||||
}; |
||||
}, |
||||
childContext: ["context"] |
||||
}); |
||||
BI.model("demo.model.parent_store", ParentStore); |
||||
|
||||
var ChildStore = BI.inherit(Fix.Model, { |
||||
context: ["context"], |
||||
computed: { |
||||
currContext: function () { |
||||
return this.model.context; |
||||
} |
||||
}, |
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = "改变后的context"; |
||||
} |
||||
} |
||||
}); |
||||
BI.model("demo.model.child_store", ChildStore); |
||||
|
||||
var Label = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.child_store"); |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.label", |
||||
text: this.model.currContext |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.label", Label); |
||||
|
||||
var Demo = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.parent_store"); |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this; |
||||
return { |
||||
type: "demo.label", |
||||
ref: function (_ref) { |
||||
self.child = _ref; |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.demo", Demo); |
||||
|
||||
var demo = BI.Test.createWidget({ |
||||
type: "demo.demo" |
||||
}); |
||||
|
||||
expect(demo.child.model.currContext).to.equal("默认context"); |
||||
demo.child.store.changeContext(); |
||||
expect(demo.model.context).to.equal("改变后的context"); |
||||
demo.destroy(); |
||||
|
||||
}); |
||||
|
||||
/** |
||||
* test_author_guy |
||||
*/ |
||||
it("异步context测试-loader的populate测试", function (done) { |
||||
|
||||
var ParentStore = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
context: "默认context" |
||||
}; |
||||
}, |
||||
childContext: ["context"] |
||||
}); |
||||
BI.model("demo.model.parent_store", ParentStore); |
||||
|
||||
var ChildStore = BI.inherit(Fix.Model, { |
||||
context: ["context"], |
||||
computed: { |
||||
currContext: function () { |
||||
return this.model.context; |
||||
} |
||||
}, |
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = "改变后的context"; |
||||
} |
||||
} |
||||
}); |
||||
BI.model("demo.model.child_store", ChildStore); |
||||
|
||||
var Label = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.child_store"); |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.label", |
||||
text: this.model.currContext |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.label", Label); |
||||
|
||||
var Demo = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.parent_store"); |
||||
}, |
||||
|
||||
render: function () { |
||||
var items = BI.map([1, 2, 3], function (i, v) { |
||||
return { |
||||
text: v, |
||||
value: v, |
||||
title: v |
||||
}; |
||||
}); |
||||
var self = this; |
||||
this.labels = {}; |
||||
return { |
||||
type: "bi.loader", |
||||
ref: function (_ref) { |
||||
self.child = _ref; |
||||
}, |
||||
itemsCreator: function (options, populate) { |
||||
setTimeout(function () { |
||||
populate(BI.map(items.slice((options.times - 1) * 10, options.times * 10), function (i, v) { |
||||
return BI.extend(v, { |
||||
type: "demo.label", |
||||
ref: function (_ref) { |
||||
self.labels[i] = _ref; |
||||
}, |
||||
height: 25 |
||||
}); |
||||
})); |
||||
}, 0); |
||||
}, |
||||
hasNext: function (options) { |
||||
return options.times * 10 < items.length; |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.demo", Demo); |
||||
|
||||
var demo = BI.Test.createWidget({ |
||||
type: "demo.demo" |
||||
}); |
||||
demo.child.populate(); |
||||
|
||||
setTimeout(function () { |
||||
expect(demo.labels[0].model.currContext).to.equal("默认context"); |
||||
demo.destroy(); |
||||
done(); |
||||
}, 0); |
||||
}); |
||||
|
||||
/** |
||||
* test_author_guy |
||||
*/ |
||||
it("异步context测试-beforeInit测试", function (done) { |
||||
|
||||
var ParentStore = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
context: "默认context" |
||||
}; |
||||
}, |
||||
childContext: ["context"] |
||||
}); |
||||
BI.model("demo.model.parent_store", ParentStore); |
||||
|
||||
var ChildStore = BI.inherit(Fix.Model, { |
||||
context: ["context"], |
||||
computed: { |
||||
currContext: function () { |
||||
return this.model.context; |
||||
} |
||||
}, |
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = "改变后的context"; |
||||
} |
||||
} |
||||
}); |
||||
BI.model("demo.model.child_store", ChildStore); |
||||
|
||||
var Label = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.child_store"); |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.label", |
||||
text: this.model.currContext |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.label", Label); |
||||
|
||||
var Demo = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.parent_store"); |
||||
}, |
||||
|
||||
beforeInit: function (callback) { |
||||
setTimeout(callback, 0); |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this; |
||||
return { |
||||
type: "demo.label", |
||||
ref: function (_ref) { |
||||
self.child = _ref; |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.demo", Demo); |
||||
|
||||
var demo = BI.Test.createWidget({ |
||||
type: "demo.demo" |
||||
}); |
||||
|
||||
setTimeout(function () { |
||||
expect(demo.child.model.currContext).to.equal("默认context"); |
||||
demo.destroy(); |
||||
done(); |
||||
}, 0); |
||||
}); |
||||
|
||||
/** |
||||
* test_author_guy |
||||
*/ |
||||
it("inject测试", function () { |
||||
|
||||
var ParentStore = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
context: "默认context" |
||||
}; |
||||
}, |
||||
childContext: ["context"] |
||||
}); |
||||
BI.model("demo.model.parent_store", ParentStore); |
||||
|
||||
var ChildStore = BI.inherit(Fix.Model, { |
||||
inject: ["context"], |
||||
computed: { |
||||
currContext: function () { |
||||
return this.model.context; |
||||
} |
||||
}, |
||||
actions: { |
||||
changeContext: function () { |
||||
this.model.context = "改变后的context"; |
||||
} |
||||
} |
||||
}); |
||||
BI.model("demo.model.child_store", ChildStore); |
||||
|
||||
var Label = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.child_store"); |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.label", |
||||
text: this.model.currContext |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.label", Label); |
||||
|
||||
var Demo = BI.inherit(BI.Widget, { |
||||
_store: function () { |
||||
return BI.Models.getModel("demo.model.parent_store"); |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this; |
||||
return { |
||||
type: "demo.label", |
||||
ref: function (_ref) { |
||||
self.child = _ref; |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.demo", Demo); |
||||
|
||||
var demo = BI.Test.createWidget({ |
||||
type: "demo.demo" |
||||
}); |
||||
|
||||
expect(demo.child.model.currContext).to.equal("默认context"); |
||||
demo.child.store.changeContext(); |
||||
expect(demo.model.context).to.equal("默认context"); |
||||
demo.destroy(); |
||||
|
||||
}); |
||||
|
||||
}); |
Loading…
Reference in new issue