Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Commit

Permalink
fix: lifetimes higher priority (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzone authored and bzone committed Sep 29, 2018
1 parent 3d0a12b commit 43318dd
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/weappx-weapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function connectComponent(states = {}, setData = 'setData') {

// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
const methods = ComponentOptions.methods || {};
const attached = methods.attached || ComponentOptions.attached;
const detached = methods.detached || ComponentOptions.detached;
const lifetimes = ComponentOptions.lifetimes || {};
const attached = lifetimes.attached || methods.attached || ComponentOptions.attached;
const detached = lifetimes.detached || methods.detached || ComponentOptions.detached;

methods.attached && delete methods.attached;
methods.detached && delete methods.detached;
Expand All @@ -45,6 +46,11 @@ function connectComponent(states = {}, setData = 'setData') {

return {
...ComponentOptions,
lifetimes: {
...lifetimes,
attached: undefined,
detached: undefined,
},
data: Object.assign(ComponentOptions.data || {}, mapState(states)),
attached() {
const store = getStore();
Expand All @@ -66,10 +72,11 @@ function connectPage(states = {}, setData = 'setData') {
return function(PageOptions) {
let unSubscribe = null;

const onLoad = PageOptions.onLoad;
const onUnload = PageOptions.onUnload;
const onShow = PageOptions.onShow;
const onHide = PageOptions.onHide;
const pageLifetimes = PageOptions.pageLifetimes || {};
const onLoad = pageLifetimes.load || PageOptions.onLoad;
const onUnload = pageLifetimes.unload || PageOptions.onUnload;
const onShow = pageLifetimes.show || PageOptions.onShow;
const onHide = pageLifetimes.hide || PageOptions.onHide;

const onStateChange = function() {
if (this.$hide) {
Expand All @@ -90,6 +97,13 @@ function connectPage(states = {}, setData = 'setData') {

return {
...PageOptions,
pageLifetimes: {
...pageLifetimes,
load: undefined,
unload: undefined,
show: undefined,
hide: undefined,
},
data: Object.assign(PageOptions.data || {}, mapState(states)),
onLoad() {
const store = getStore();
Expand Down

0 comments on commit 43318dd

Please sign in to comment.