@@ -10,27 +10,54 @@ import { Transform } from 'stream';
1010 * import Animation from 'kittik-animation-basic';
1111 *
1212 * export default class Print extends Animation {
13- * constructor(...args) {
14- * super(...args);
15- * }
16- *
1713 * animate(chunk, cb) {
1814 * // Do your logic here for animate the shape rendering and call cb
1915 * cb(chunk);
2016 * }
2117 * };
2218 */
2319export default class Basic extends Transform {
24- _enabled = false ;
20+ _options = { } ;
2521
2622 /**
27- * Constructor is responsible for initializing base properties.
28- * Don't forgot to call `super(...args)` when extending from this class.
29- *
3023 * @constructor
3124 */
3225 constructor ( ) {
3326 super ( ) ;
27+
28+ this . disable ( ) ;
29+ }
30+
31+ /**
32+ * Get option value.
33+ *
34+ * @param {String } path Path can be set with dot-notation
35+ * @returns {* }
36+ */
37+ get ( path ) {
38+ return path . split ( '.' ) . reduce ( ( obj , key ) => obj [ key ] , this . _options ) ;
39+ }
40+
41+ /**
42+ * Set new option value.
43+ *
44+ * @param {String } path Path can be set with dot-notation
45+ * @param {* } value Value that need to be written to the options object
46+ * @returns {Basic }
47+ */
48+ set ( path , value ) {
49+ let obj = this . _options ;
50+ let tags = path . split ( '.' ) ;
51+ let len = tags . length - 1 ;
52+
53+ for ( let i = 0 ; i < len ; i ++ ) {
54+ if ( typeof obj [ tags [ i ] ] === 'undefined' ) obj [ tags [ i ] ] = { } ;
55+ obj = obj [ tags [ i ] ] ;
56+ }
57+
58+ obj [ tags [ len ] ] = value ;
59+
60+ return this ;
3461 }
3562
3663 /**
@@ -39,7 +66,7 @@ export default class Basic extends Transform {
3966 * @returns {Basic }
4067 */
4168 enable ( ) {
42- this . _enabled = true ;
69+ this . set ( 'enabled' , true ) ;
4370 return this ;
4471 }
4572
@@ -49,7 +76,7 @@ export default class Basic extends Transform {
4976 * @returns {Basic }
5077 */
5178 disable ( ) {
52- this . _enabled = false ;
79+ this . set ( 'enabled' , false ) ;
5380 return this ;
5481 }
5582
@@ -59,7 +86,7 @@ export default class Basic extends Transform {
5986 * @returns {Boolean }
6087 */
6188 isEnabled ( ) {
62- return ! ! this . _enabled ;
89+ return ! ! this . get ( 'enabled' ) ;
6390 }
6491
6592 /**
@@ -68,7 +95,7 @@ export default class Basic extends Transform {
6895 * @returns {Boolean }
6996 */
7097 isDisabled ( ) {
71- return ! this . _enabled ;
98+ return ! this . get ( 'enabled' ) ;
7299 }
73100
74101 /**
@@ -89,9 +116,9 @@ export default class Basic extends Transform {
89116 /**
90117 * Process each chunk of control symbols before piping into next item in the animations chain.
91118 *
92- * @param chunk
93- * @param encoding
94- * @param cb
119+ * @param { Buffer|String } chunk
120+ * @param { String } encoding
121+ * @param { Function } cb
95122 * @private
96123 */
97124 _transform ( chunk , encoding , cb ) {
0 commit comments