stampit API
Search…
@stamp/required
Insist on a method/property/staticProperty/configuration presence
This stamp (aka behavior) will throw if a method (property, staticProperty, configuration, etc) is missing at object creation.

Usage

1
import Required from '@stamp/required'
2
3
const InsistOnRedrawMethod = Required.required({methods: {redraw: Required}})
Copied!
Or if you don't want to import the stamp you can import only the method:
1
import {required} from '@stamp/required'
2
const InsistOnRedrawMethod = required({methods: {redraw: required}})
Copied!

API

Static methods

required

Setup which things are required stamp.required({METATYPE: {KEY: required}}) -> Stamp

Example

1
import stampit from '@stamp/it'
2
import Required, {required} from '@stamp/required'
3
4
const requiredConfigurationDifficulty = required({configuration: {difficulty: required}})
5
const requiredMethodMove = required({methods: {move: Required}})
6
const requiredPropertyGuild = Required.required({properties: {guild: required}})
7
8
let Paladin = stampit({
9
props: {
10
mana: 50,
11
strength: 50,
12
health: 100
13
}
14
})
15
16
const paladin = Paladin() // ok
17
18
Paladin = Paladin.compose(
19
requiredConfigurationDifficulty,
20
requiredMethodMove,
21
requiredPropertyGuild
22
)
23
24
const paladin = Paladin() // THROWS - Required: There must be difficulty in this stamp configuration
25
26
Paladin = Paladin.conf({ difficulty: 5 })
27
28
const paladin = Paladin() // THROWS - Required: There must be move in this stamp methods
29
30
Paladin = Paladin.methods({
31
move(x, y) {
32
// ... implementation
33
}
34
})
35
36
const paladin = Paladin() // THROWS - Required: There must be guild in this stamp properties
37
38
Paladin = Paladin.props({ guild: 'Warriors of Light' })
39
40
const paladin = Paladin() // ok
Copied!
Last modified 3yr ago