@xcore24/extended-object-props
v1.0.2
Published
TypeScript library implementing the Extended object properties pattern
Downloads
7
Maintainers
Readme
extended-object-props
extended-object-props
is TypeScript library implementing the Extended object properties pattern.
Installation
To start using extended-object-props install the npm package:
npm install @xcore24/extended-object-props
Basic Usage
import { ExtendObjectProps } from "@xcore24/extended-object-props";
interface IExendedPropertiesClass {
[key: string | symbol]: any
}
class ClassA implements IExendedPropertiesClass {
foo: string = 'foo'
bar: string = 'bar'
}
class ClassZ implements IExendedPropertiesClass {
a: string = 'aaaa'
b: string = 'bbb'
}
class ClassB extends ExtendObjectProps {
constructor(obj: {}) {
super()
this.addProps(obj)
this.addProps(obj, 'obj')
this.publicProps.add('xyz')
}
get xyz() {
return 'xyz'
}
}
const objectA = new ClassA()
const objectB = new ClassB(objectA)
const objB = objectB as IExendedPropertiesClass
console.log(objB.foo)
console.log(objB.obj)
console.log(objB.obj.bar)
objB.obj.bar = 'bar2'
console.log(objB.obj.bar)
console.log(JSON.stringify(objectB))
const classZ = new ClassZ()
objB.addProp('z', classZ)
objectB.publicProps.add('z')
console.log(['extended-prop:example:1'], objectB.getProps('z' as never).a)
console.log(['extended-prop:example:2'], objB.z.a)
console.log(JSON.stringify(objB))