File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,12 +17,9 @@ export default class Shape {
1717 _options = { } ;
1818
1919 /**
20- * Constructor is responsible for initializing base properties.
21- * Don't forgot to call `super(...args)` when extending from this class.
22- *
2320 * @constructor
2421 * @param {Object } [options]
25- * @param {String } [options.text] Text that will be rendered in shape
22+ * @param {String } [options.text] Text that will be rendered in the shape
2623 * @param {Number } [options.width] Shape width
2724 * @param {Number } [options.height] Shape height
2825 * @param {Number } [options.x] Absolute coordinate X
@@ -56,12 +53,22 @@ export default class Shape {
5653 /**
5754 * Set new option value.
5855 *
59- * @param {String } path
56+ * @param {String } path Path can be set with dot-notation
6057 * @param {* } value
6158 * @returns {Shape }
6259 */
6360 set ( path , value ) {
64- this . _options [ path ] = value ;
61+ let obj = this . _options ;
62+ let tags = path . split ( '.' ) ;
63+ let len = tags . length - 1 ;
64+
65+ for ( let i = 0 ; i < len ; i ++ ) {
66+ if ( typeof obj [ tags [ i ] ] === 'undefined' ) obj [ tags [ i ] ] = { } ;
67+ obj = obj [ tags [ i ] ] ;
68+ }
69+
70+ obj [ tags [ len ] ] = value ;
71+
6572 return this ;
6673 }
6774
Original file line number Diff line number Diff line change @@ -14,6 +14,15 @@ describe('Shape', () => {
1414 assert . equal ( shape . getText ( ) , 'test' ) ;
1515 } ) ;
1616
17+ it ( 'Should properly get/set from options object' , ( ) => {
18+ let shape = new Shape ( ) ;
19+ assert . equal ( shape . get ( 'text' ) , '' ) ;
20+ assert . instanceOf ( shape . set ( 'animation.name' , 'print' ) , Shape ) ;
21+ assert . equal ( shape . get ( 'animation.name' ) , 'print' ) ;
22+ assert . instanceOf ( shape . set ( 'animation.name' , 'test' ) , Shape ) ;
23+ assert . equal ( shape . get ( 'animation.name' ) , 'test' ) ;
24+ } ) ;
25+
1726 it ( 'Should properly get/set text' , ( ) => {
1827 let shape = new Shape ( ) ;
1928 assert . equal ( shape . getText ( ) , '' ) ;
You can’t perform that action at this time.
0 commit comments