From 20a779a38425a5711b6a7344ec1e30ccc77b1396 Mon Sep 17 00:00:00 2001 From: zsmj1994 Date: Tue, 13 Oct 2020 14:37:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20chore:=20upda?= =?UTF-8?q?te=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/config/fix.js | 7 ++- demo/js/fix-2.0/context.js | 10 +++-- demo/js/fix-2.0/inject.js | 87 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 demo/js/fix-2.0/inject.js diff --git a/demo/js/config/fix.js b/demo/js/config/fix.js index 8a69eaed8..6eacf396e 100644 --- a/demo/js/config/fix.js +++ b/demo/js/config/fix.js @@ -46,4 +46,9 @@ Demo.FIX_CONFIG = [{ pId: 7, text: "场景", value: "demo.fix_scene" -}]; \ No newline at end of file +}, { + id: 80, + pId: 7, + text: "inject", + value: "demo.fix_inject" +}]; diff --git a/demo/js/fix-2.0/context.js b/demo/js/fix-2.0/context.js index 475a820bb..b248b502c 100644 --- a/demo/js/fix-2.0/context.js +++ b/demo/js/fix-2.0/context.js @@ -8,6 +8,8 @@ childContext: ["context"] }); + BI.model("demo.model.context.parent_store",ParentStore) + var ChildStore = BI.inherit(Fix.Model, { context: ["context"], computed: { @@ -22,9 +24,11 @@ } }); + BI.model("demo.model.context.child_store",ChildStore) + var Child = BI.inherit(BI.Widget, { _store: function () { - return new ChildStore(); + return BI.Models.getModel("demo.model.context.child_store"); }, watch: { currContext: function (val) { @@ -53,7 +57,7 @@ var Parent = BI.inherit(BI.Widget, { _store: function () { - return new ParentStore(); + return BI.Models.getModel("demo.model.context.parent_store"); }, render: function () { var self = this; @@ -72,4 +76,4 @@ }); BI.shortcut("demo.fix_context", Parent); -}()); \ No newline at end of file +}()); diff --git a/demo/js/fix-2.0/inject.js b/demo/js/fix-2.0/inject.js new file mode 100644 index 000000000..3c7b27fcb --- /dev/null +++ b/demo/js/fix-2.0/inject.js @@ -0,0 +1,87 @@ +(function () { + var ParentStore = BI.inherit(Fix.Model, { + state: function () { + return { + context: { + one: { + key: "one.key" + } + } + }; + }, + childContext: ["context"] + }); + + 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 = { + two: { + key: "two.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(); + } + }; + }, + mounted: function () { + + } + }); + + 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.absolute", + items: [{ + el: { + type: "demo.fix_inject_child" + } + }] + }; + }, + mounted: function () { + + } + }); + + BI.shortcut("demo.fix_inject", Parent); +}());