Skip to content

Commit

Permalink
native canvas 提供了事件支持,故移除 my-f2 的事件封装。
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Oct 9, 2018
1 parent 81df1cf commit 19389a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/my-f2",
"version": "1.1.2",
"version": "1.2.0-beta.1",
"description": "F2 for alipay mini-program",
"browser": "build/my-f2.js",
"main": "build/my-f2.js",
Expand Down Expand Up @@ -91,7 +91,6 @@
"silent": false
},
"dependencies": {
"@antv/f2": "~3.2.2",
"wolfy87-eventemitter": "^5.2.4"
"@antv/f2": "~3.2.2"
}
}
16 changes: 14 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
const Renderer = require('./renderer');
const Core = require('@antv/f2/lib/core'); // 引入 F2 的核心包

const EVENTS_MAP = {
touchstart: 'touchStart',
touchmove: 'touchMove',
touchend: 'touchEnd',
touchcancel: 'touchCancel'
};

// 为小程序封装事件机制
Core.Util.addEventListener = function(source, type, listener) {
source.addListener(type, listener);
const context = source.getContext('2d');
type = EVENTS_MAP[type]; // 支付宝小程序事件名为驼峰结构
context.addEventListener(type, listener);
};

Core.Util.removeEventListener = function(source, type, listener) {
source.removeListener(type, listener);
const context = source.getContext('2d');
type = EVENTS_MAP[type]; // 支付宝小程序事件名为驼峰结构
context.removeEventListener(type, listener);
};

Core.Util.createEvent = function(event, chart) {
Expand Down
4 changes: 1 addition & 3 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @version 1.0.0
*/

const EventEmitter = require('wolfy87-eventemitter');
const CAPITALIZED_ATTRS_MAP = {
fillStyle: 'FillStyle',
fontSize: 'FontSize',
Expand All @@ -19,9 +18,8 @@ const CAPITALIZED_ATTRS_MAP = {
textBaseline: 'TextBaseline'
};

class Renderer extends EventEmitter {
class Renderer {
constructor(myCtx) {
super();
const self = this;
self.ctx = myCtx;
self.style = {}; // just mock
Expand Down

0 comments on commit 19389a6

Please sign in to comment.