update Konva.Node.create flow

This commit is contained in:
lavrton 2015-08-28 10:29:52 +07:00
parent 981f245833
commit 026423402d
3 changed files with 22 additions and 4 deletions

View File

@ -4,11 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Not released][Not released]
### Added
- RGBA filter =. Thanls to [@codefo](https://github.com/codefo)
### Fixed
- Correct calculation in `getClientRect` method of `Konva.Line` and `Konva.Container`.
### Changed
- Dragging now works much better. If your pointer is out of stage content dragging will still continue.
- `Konva.Node.create` not works with objects.
## [0.9.5][2015-05-28]

View File

@ -1699,7 +1699,7 @@
});
/**
* create node with JSON string. De-serializtion does not generate custom
* create node with JSON string or an Object. De-serializtion does not generate custom
* shape drawing functions, images, or event handlers (this would make the
* serialized object huge). If your app uses custom shapes, images, and
* event handlers (it probably does), then you need to select the appropriate
@ -1707,12 +1707,15 @@
* and setImage() methods
* @method
* @memberof Konva.Node
* @param {String} json
* @param {String|Object} json string or object
* @param {Element} [container] optional container dom element used only if you're
* creating a stage node
*/
Konva.Node.create = function(json, container) {
return this._createNode(JSON.parse(json), container);
Konva.Node.create = function(data, container) {
if (Konva.Util._isString(data)) {
data = JSON.parse(data);
}
return this._createNode(data, container);
};
Konva.Node._createNode = function(obj, container) {
var className = Konva.Node.prototype.getClassName.call(obj),

View File

@ -2167,6 +2167,17 @@ suite('Node', function() {
assert.equal(stage.toJSON(), json);
});
// ======================================================
test('create node using object', function() {
var node = new Konva.Circle({
id: 'test',
radius: 10
});
var clone = Konva.Node.create(node.toObject());
assert.deepEqual(node.toObject(), clone.toObject());
});
// ======================================================
test('serialize stage with custom shape', function() {
var stage = addStage();