setunset
The "Set Unset" tool acts similar to the ctx.save() method, by applying changes to the context, and then unsetting after usage.
This allows the switching of a property of the context with set and unset
values previously assigned to changed properties are reapplied - essentially wrapping
some drawing with context changes.
su = new SetUnset({
lineWidth: 10
})
// lineWidth == ...
su.set(ctx)
// lineWidth == 10
su.unset(ctx)
// lineWidth == ...
Implement shortcuts:
class Stroke extends SetUnset {
getOpts() {
let supported = new Set([
, "lineWidth"
])
let map = {
color: 'strokeStyle'
}
let functional = {
dash: 'lineDashKeyApply'
}
return [supported, map, functional]
}
}
st = new Stroke({
color: 'red'
})
Meta Data
| filepath_exists | True |
| path | setunset |
| filepath | setunset.js |
| clean_files | () |
-
ClassDeclarationclass
SetUnset
extends Noneclass comments:The "Set Unset" tool acts similar to the _ctx.save()_ method, by applying changes to the context, and then _unsetting_ after usage. This allows the _switching_ of a property of the context with `set` and `unset` values previously assigned to changed properties are reapplied - essentially _wrapping_ some drawing with context changes. su = new SetUnset({ lineWidth: 10 }) // lineWidth == ... su.set(ctx) // lineWidth == 10 su.unset(ctx) // lineWidth == ... Implement shortcuts: class Stroke extends SetUnset { getOpts() { let supported = new Set([ , "lineWidth" ]) let map = { color: 'strokeStyle' } let functional = { dash: 'lineDashKeyApply' } return [supported, map, functional] } } st = new Stroke({ color: 'red' })Perform _stroke_ with styling and stoking; but with a convenient on/off without using the context switcher.-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])when _settings_ to the ctx + first check if its a raw prop, + else then resolve from the map. + keep the last value + Apply through the given function + accept a optional return function, to call during unset. Therefore the stroker has a _state_ This should occur _early_ such that the _set_ here runs a chain of on/off functions in a map. Which means: 1. for each key resolve ctx (real prop map key), on method, off method 2. store those until _set_ 3. iter on map; calling each func with the ctx and the value 4. iter off map, calling each with the stored value, reapplying in the func.
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])Receive a ctx key property (e.g. lineWidth) and apply the newValue Return the previously applied value and a function to remove reverse change.
-
dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])the newValue given is the original value applied to this key, before the change occured (the cached value). Therefore the _remove_ is identical to the _apply_.