Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Utils.define = (layer, property, value, callback, validation, error) ->
validation ?= -> true
error ?= "Layer #{}'s property '#{property}' was given the wrong value type."
Object.defineProperty layer,
get: -> return layer["_#{property}"]
set: (value) ->
if value?
if not validation(value) then throw error
return if value is layer["_#{property}"]
layer["_#{property}"] = value
layer.emit("change:#{property}", value, layer)
configurable: true
if callback? and typeof callback is 'function'
layer.on("change:#{property}", callback)
layer[property] = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment