Browse Source

Avoid binding 3rd party property to c3 API - #647

pull/682/merge
Masayuki Tanaka 10 years ago
parent
commit
a5461140f5
  1. 4
      c3.js
  2. 2
      c3.min.js
  3. 27
      spec/core-spec.js
  4. 4
      src/core.js

4
c3.js

@ -14,12 +14,12 @@
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
for (var key in fn) { Object.keys(fn).forEach(function (key) {
target[key] = fn[key].bind(argThis); target[key] = fn[key].bind(argThis);
if (Object.keys(fn[key]).length > 0) { if (Object.keys(fn[key]).length > 0) {
bindThis(fn[key], target[key], argThis); bindThis(fn[key], target[key], argThis);
} }
} });
})(c3_chart_fn, this, this); })(c3_chart_fn, this, this);
} }

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

27
spec/core-spec.js

@ -8,10 +8,7 @@ describe('c3 chart', function () {
var chart, d3; var chart, d3;
beforeEach(function () { var args = {
window.initDom();
chart = window.c3.generate({
data: { data: {
columns: [ columns: [
['data1', 30, 200, 100, 400, 150, 250], ['data1', 30, 200, 100, 400, 150, 250],
@ -19,16 +16,34 @@ describe('c3 chart', function () {
['data3', 150, 120, 110, 140, 115, 125] ['data3', 150, 120, 110, 140, 115, 125]
] ]
} }
}); };
beforeEach(function (done) {
chart = window.initChart(chart, args, done);
d3 = chart.internal.d3; d3 = chart.internal.d3;
}); });
describe('init', function () {
it('should be created', function () { it('should be created', function () {
var svg = d3.select('#chart svg'); var svg = d3.select('#chart svg');
expect(svg).not.toBeNull(); expect(svg).not.toBeNull();
}); });
it('should set 3rd party property to Function', function () {
Function.prototype.$extIsFunction = true;
expect(true).toBeTruthy();
});
it('should be created even if 3rd party property has been set', function () {
var svg = d3.select('#chart svg');
expect(svg).not.toBeNull();
});
});
describe('size', function () {
it('should have same width', function () { it('should have same width', function () {
var svg = d3.select('#chart svg'); var svg = d3.select('#chart svg');
expect(+svg.attr('width')).toBe(640); expect(+svg.attr('width')).toBe(640);
@ -40,3 +55,5 @@ describe('c3 chart', function () {
}); });
}); });
});

4
src/core.js

@ -9,12 +9,12 @@ function Chart(config) {
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
for (var key in fn) { Object.keys(fn).forEach(function (key) {
target[key] = fn[key].bind(argThis); target[key] = fn[key].bind(argThis);
if (Object.keys(fn[key]).length > 0) { if (Object.keys(fn[key]).length > 0) {
bindThis(fn[key], target[key], argThis); bindThis(fn[key], target[key], argThis);
} }
} });
})(c3_chart_fn, this, this); })(c3_chart_fn, this, this);
} }

Loading…
Cancel
Save