thisless
v1.0.1
Published
allow using classes as blank objects
Downloads
2
Readme
thisless
allow using classes as blank objects
- statetree for mobx-state-tree
- index for the functions to wrap classes in
thisless
,selfless
, or use as decorators - test for usage of the api
- snippet all-in-one copy paste to try running it in your setup with jest
exports
const {
selfless,
thisless,
toBlankObj,
getOwnPrototypeNames,
NATIVE_PROPS_NON_ENUMERABLE,
isUndefined,
} = require('thisless')
// for adding wrappers to mobx-state-tree prototype
// require('thisless/statetree')
why?
- can use decorators
- no commas required
- no paren wrappers required
- can add metadata in a cleaner shorter more understandable syntax
example
these are all the same
// setup
const $self = {igloo: 10}
const getPreThisLess = self => @thisless class {
get aboot() {
return 100
}
moose() {
return self.igloo
}
}
const getThisLessed = self => class {
get aboot() {
return 100
}
moose() {
return self.igloo
}
}
const getSelflessed = self => class {
get aboot() {
return 100
}
moose() {
return self.igloo
}
}
const getES6Obj = self => ({
get aboot() {
return 100
},
moose() {
return self.igloo
},
})
const getReturnedInitializedObj = self => {
return {
get aboot() {
return 100
},
moose() {
return self.igloo
},
}
}
usage
// common usage as objects not classes no thisless needed
const ES6Obj = getES6Obj($self)
const Initialized = getReturnedInitializedObj($self)
// to do the same as ^ with classes
const SelfLessed = selfless(getSelflessed($self))
const ThisLessed = thisless(getThisLessed($self))
const ThisLessedDecorated = getPreThisLess($self)