Kinetic.Animation constructor now just requires a function and optional node. No more config object

This commit is contained in:
Eric Rowell
2012-11-15 21:30:58 -08:00
parent 694ced6b7a
commit 1913fed33b
7 changed files with 25 additions and 40 deletions

View File

@@ -1,14 +1,16 @@
#Building the KineticJS library
To build the library, you need to have Ruby and Rubygems installed. After that, run `gem install thor`, `gem install json_pure`, and `gem install uglifier` to install the dependencies.
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev current` will produce `kinetic-current.js`. To build a minified version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012"`).
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev current` will produce `kinetic-current.js`. To build a minified version of the library, run `thor build:prod VERSION`.
If you add a file in the src directory, be sure to add the filename to the filename array in the Thorfile.
#Tests
#Testing
To run unit tests, you'll need to build the `unitTests.js` file by running `thor build:test` and then opening `unitTests.html` in the `tests/html` directory. The other tests can be ran directly by opening `functionalTests.html`, `manualTests.html`, or `performanceTests.html` in the `tests/html` directory. Unit, functional, and performance tests output the results to the console via `console.log()` so be sure to have it open.
To add / modify unit tests, be sure to do so in the `tests/js/unit` directory, because these are the source test files that are concatenated together when building `unitTests.js`. Use `test()` for hard tests which will throw an error if something fails, and use `warn()` for soft tests that will allow the tests to continue if the test condition fails. The `warn()` method is great for tests that will have different results in different browsers, such as canvas data url comparisons, text metric dimensions, etc. All tests should pass in Google Chrome with no warnings, and all tests should pass with some warnings in other browsers.
TIP: prepend a test name with a `*` to only run that particular test, or prepend a test name with `x` to omit that test.
#Pull Requests
I'd be happy to review any pull requests that may better the KineticJS project, in particular if you have a bug fix, enhancement, or a new shape (see `src/shapes` for examples). Before doing so, please first make sure that all of the unit tests and functional tests pass.

View File

@@ -3,17 +3,13 @@
* animations
* @constructor
* @augments Kinetic.Container
* @param {Object} config
* @param {Function} config.func function to be executed on each animation frame
* @param {Function} func function executed on each animation frame
* @param {Kinetic.Node} [node] node to be redrawn.  Specifying a node will improve
* draw performance.  This can be a shape, a group, a layer, or the stage.
*/
Kinetic.Animation = function(config) {
if(!config) {
config = {};
}
for(var key in config) {
this[key] = config[key];
}
Kinetic.Animation = function(func, node) {
this.func = func;
this.node = node;
this.id = Kinetic.Animation.animIdCounter++;
};
/*

View File

@@ -94,7 +94,7 @@ Test.prototype = {
// loop through tests
for(var key in tests) {
if(!testOnlySpecial || key.charAt(0) === '*') {
if(key.charAt(0) !== 'x' && (!testOnlySpecial || key.charAt(0) === '*')) {
var obj = this.addTestContainer(key);
this.counter++;
console.log(this.counter + ') ' + key);

View File

@@ -167,12 +167,9 @@ Test.Modules.MANUAL = {
// in ms
var centerX = stage.getWidth() / 2 - 100 / 2;
var anim = new Kinetic.Animation({
func: function(frame) {
var anim = new Kinetic.Animation(function(frame) {
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
layer.draw();
}
});
}, layer);
anim.start();
@@ -1292,12 +1289,10 @@ Test.Modules.MANUAL = {
layer.add(group);
stage.add(layer);
var anim = new Kinetic.Animation({
func: function() {
var anim = new Kinetic.Animation(function() {
rect.rotate(0.01);
layer.draw();
}
});
}, layer);
anim.start();
},
'STAGE - hide stage': function(containerId) {

View File

@@ -50,13 +50,11 @@ Test.Modules.PERFORMANCE = {
// in ms
var centerX = stage.getWidth() / 2 - 100 / 2;
var anim = new Kinetic.Animation({
func: function(frame) {
var anim = new Kinetic.Animation(function(frame) {
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
layer.draw();
//console.log(frame.timeDiff)
}
});
}, layer);
anim.start();
@@ -67,7 +65,7 @@ Test.Modules.PERFORMANCE = {
anim.start();
}, 4000);
},
'*DRAWING - draw 10,000 small circles with tooltips': function(containerId) {
'DRAWING - draw 10,000 small circles with tooltips': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,

View File

@@ -29,12 +29,9 @@ Test.Modules.ANIMATION = {
// in ms
var centerX = stage.getWidth() / 2 - 100 / 2;
var anim = new Kinetic.Animation({
func: function(frame) {
var anim = new Kinetic.Animation(function(frame) {
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
layer.draw();
}
});
}, layer);
var a = Kinetic.Animation;
test(a.animations.length === 0, 'should be no animations running');

View File

@@ -23,12 +23,9 @@ Test.Modules.TRANSITION = {
var period = 1000;
var centerX = 0;
var anim = new Kinetic.Animation({
func: function(frame) {
var anim = new Kinetic.Animation(function(frame) {
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
layer.draw();
}
});
}, layer);
anim.start();
anim.stop();