Skip to content

Commit

Permalink
hide value
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 3, 2023
1 parent 2bbe676 commit 27389f8
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions packages/rich-text/src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,14 @@
import { toHTMLString } from './to-html-string';
export class RichTextString {
constructor( { value, ...settings } ) {
for ( const key in value ) {
Object.defineProperty( this, key, {
value: value[ key ],
enumerable: true,
} );
}

for ( const key in settings ) {
Object.defineProperty( this, key, {
value: settings[ key ],
} );
}
}

toString() {
if ( ! this.cache ) {
Object.defineProperty( this, 'cache', {
value: toHTMLString( {
value: { ...this },
multilineTag: this.multilineTag,
preserveWhiteSpace: this.preserveWhiteSpace,
} ),
} );
}

return this.cache;
let cache;
this.__unstableGetValue = () => value;
this.toString = () => {
if ( ! cache ) {
cache = toHTMLString( { value, ...settings } );
}
return cache;
};
}
}

Expand Down

0 comments on commit 27389f8

Please sign in to comment.