Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* build(miniapp-render): publish version 1.2.2

* fix(miniapp): not distinguish event between alipay and wechat

* fix: page render

* chore: opitimize code

* feat: init

* fix: first render opportunity

* docs(miniapp): add multiple demos

* fix: first render callback

* refactor(miniapp): rename behavior

* chore(example): resolve conflict

* chore(miniapp): ,

remove inside build-plugin

* chore(example): remove console.log

Co-authored-by: fushen <[email protected]>
  • Loading branch information
ChrisCindy and SoloJiang authored Aug 20, 2020
1 parent a67b75c commit 247459e
Show file tree
Hide file tree
Showing 32 changed files with 123 additions and 186 deletions.
3 changes: 1 addition & 2 deletions examples/app-lifecycle/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
3 changes: 1 addition & 2 deletions examples/app-lifecycle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
3 changes: 1 addition & 2 deletions examples/page-lifecycle-with-router/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
3 changes: 1 addition & 2 deletions examples/page-lifecycle-with-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
3 changes: 1 addition & 2 deletions examples/with-miniapp-native-custom-component/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
3 changes: 1 addition & 2 deletions examples/with-miniapp-native-custom-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
3 changes: 1 addition & 2 deletions examples/with-miniapp-native-page/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
3 changes: 1 addition & 2 deletions examples/with-miniapp-native-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Component({
props: {
pluginName: ''
pluginName: 'plugin'
},
methods: {
onClick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Page({});
Page({});
3 changes: 1 addition & 2 deletions examples/with-miniapp-plugin-component/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"buildType": "runtime"
}
}
],
"@ali/build-plugin-rax-app-def"
]
]
}
3 changes: 1 addition & 2 deletions examples/with-miniapp-plugin-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"eslint-config-rax": "^0.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-module": "^0.1.0",
"eslint-plugin-react": "^7.18.0",
"@ali/build-plugin-rax-app-def": "^1.0.2"
"eslint-plugin-react": "^7.18.0"
},
"private": true,
"originTemplate": "@rax-materials/scaffolds-app-js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
console.log('Hello plugin!');
},
answer: 42
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ Page({
onShareAppMessage: function() {

}
});
});
2 changes: 1 addition & 1 deletion packages/miniapp-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniapp-render",
"version": "1.2.1",
"version": "1.2.2",
"description": "DOM simulator for MiniApp",
"files": [
"dist"
Expand Down
12 changes: 6 additions & 6 deletions packages/miniapp-render/src/bridge/createEventProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getPageId(internal, pageId) {
return props && props.r.pageId;
}

export default function(pageId) {
export default function() {
const config = {};
// Add get DOM Node from event method
config.getDomNodeFromEvt = getDomNodeFromEvt;
Expand All @@ -32,7 +32,7 @@ export default function(pageId) {
// Add reactive event define which will bubble
baseEvents.forEach(({ name, extra = null, eventName }) => {
config[name] = function(evt) {
const __pageId = getPageId(this, pageId);
const __pageId = getPageId(this, this.data.pageId);
const document = cache.getDocument(__pageId);
if (document && document.__checkEvent(evt)) {
const nodeId = evt.currentTarget.dataset.privateNodeId;
Expand All @@ -43,7 +43,7 @@ export default function(pageId) {
// Add reactive event define which won't bubble
handlesMap.simpleEvents.forEach(({ name, eventName }) => {
config[name] = function(evt) {
const __pageId = getPageId(this, pageId);
const __pageId = getPageId(this, this.data.pageId);
const nodeId = evt.currentTarget.dataset.privateNodeId;
const targetNode = cache.getNode(__pageId, nodeId);
if (!targetNode) return;
Expand All @@ -54,15 +54,15 @@ export default function(pageId) {
// Add reactive event define which only trigger once
handlesMap.singleEvents.forEach(({ name, eventName }) => {
config[name] = function(evt) {
const __pageId = getPageId(this, pageId);
const __pageId = getPageId(this, this.data.pageId);
this.callSingleEvent(eventName, evt, __pageId);
};
});

// Add reactive event define which only trigger once and need middleware
handlesMap.functionalSingleEvents.forEach(({ name, eventName, middleware }) => {
config[name] = function(evt) {
const __pageId = getPageId(this, pageId);
const __pageId = getPageId(this, this.data.pageId);
const domNode = this.getDomNodeFromEvt(eventName, evt, __pageId);
if (!domNode) return;
middleware.call(this, evt, domNode);
Expand All @@ -73,7 +73,7 @@ export default function(pageId) {
// Add reactive event define which complex
handlesMap.complexEvents.forEach(({ name, eventName, middleware }) => {
config[name] = function(evt) {
const __pageId = getPageId(this, pageId);
const __pageId = getPageId(this, this.data.pageId);
const domNode = this.getDomNodeFromEvt(eventName, evt, __pageId);
if (!domNode) return;
middleware.call(this, evt, domNode, __pageId, evt.currentTarget.dataset.privateNodeId);
Expand Down
12 changes: 6 additions & 6 deletions packages/miniapp-render/src/bridge/events/callEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function(eventName, evt, extra, pageId, nodeId) {

if (!targetDomNode)
targetDomNode = domNode.querySelector(
'builtIn-component[behavior=switch]'
'builtIn-component[_behavior=switch]'
);
}

Expand All @@ -47,7 +47,7 @@ export default function(eventName, evt, extra, pageId, nodeId) {
} else if (targetDomNode.tagName === 'BUILTIN-COMPONENT') {
if (checkEventAccessDomNode(evt, targetDomNode, domNode)) return;

const behavior = targetDomNode.behavior;
const behavior = targetDomNode._behavior;
if (behavior === 'switch') {
const checked = !targetDomNode.getAttribute('checked');
targetDomNode.setAttribute('checked', checked);
Expand All @@ -61,7 +61,7 @@ export default function(eventName, evt, extra, pageId, nodeId) {
} else if (
(domNode.tagName === 'BUTTON' ||
domNode.tagName === 'BUILTIN-COMPONENT' &&
domNode.behavior === 'button') &&
domNode._behavior === 'button') &&
evt.type === 'click' &&
!isCapture
) {
Expand All @@ -84,13 +84,13 @@ export default function(eventName, evt, extra, pageId, nodeId) {
'textarea[name]'
);
const switchList = form
.querySelectorAll('builtin-component[behavior=switch]')
.querySelectorAll('builtin-component[_behavior=switch]')
.filter((item) => !!item.getAttribute('name'));
const sliderList = form
.querySelectorAll('builtin-component[behavior=slider]')
.querySelectorAll('builtin-component[_behavior=slider]')
.filter((item) => !!item.getAttribute('name'));
const pickerList = form
.querySelectorAll('builtin-component[behavior=picker]')
.querySelectorAll('builtin-component[_behavior=picker]')
.filter((item) => !!item.getAttribute('name'));

if (type === 'submit') {
Expand Down
24 changes: 19 additions & 5 deletions packages/miniapp-render/src/builtInComponents/swiper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default {
// eslint-disable-next-line import/no-extraneous-dependencies
import { isMiniApp, isWeChatMiniProgram } from 'universal-env';

const swiper = {
name: 'swiper',
props: [{
name: 'indicator-dots',
Expand Down Expand Up @@ -82,10 +85,6 @@ export default {
singleEvents: [{
name: 'onSwiperTransition',
eventName: 'transition'
},
{
name: 'onSwiperAnimationfinish',
eventName: 'animationfinish'
}],
functionalSingleEvents: [
{
Expand All @@ -97,3 +96,18 @@ export default {
}
]
};

if (isMiniApp) {
swiper.singleEvents.push({
name: 'onSwiperAnimationEnd',
eventName: 'animationEnd'
});
}
if (isWeChatMiniProgram) {
swiper.singleEvents.push({
name: 'onSwiperAnimationFinish',
eventName: 'animationfinish'
});
}

export default swiper;
9 changes: 5 additions & 4 deletions packages/miniapp-render/src/createConfig/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cache from '../utils/cache';
export default function(init, config) {
cache.setConfig(config);
const appConfig = {
launched: false,
launched: isMiniApp,
onLaunch(options) {
const window = createWindow();
cache.setWindow(window);
Expand All @@ -16,9 +16,9 @@ export default function(init, config) {
if (isMiniApp) {
// Use page route as pageId key word
// eslint-disable-next-line no-undef
const currentPageId = `${getCurrentPages()[0].route}-0`;
const currentPageId = `${getCurrentPages()[0].route}-1`;
const currentDocument = createDocument(currentPageId);
window.__pageId = currentPageId;
this.__pageId = window.__pageId = currentPageId;

init(window, currentDocument);
window.$$trigger('launch', {
Expand All @@ -41,7 +41,8 @@ export default function(init, config) {
this.window = window;
},
onShow(options) {
if (this.window) {
if (this.window && this.launched) {
this.__showOptions = options;
this.window.$$trigger('appshow', {
event: {
options,
Expand Down
Loading

0 comments on commit 247459e

Please sign in to comment.