JSFiddle - React, Tailwind, and code Playground
by stoodder
JavaScript
isObject = (object) -> object? and Object::toString.call( object ) is "[object Object]"
isFunction = (object) -> object? and Object::toString.call( object ) is "[object Function]"
isBoolean = (object) -> object? and Object::toString.call( object ) is "[object Boolean]"
isArray = (object) -> object? and Object::toString.call( object ) is "[object Array]"
isString = (object) -> object? and Object::toString.call( object ) is "[object String]"
isNumber = (object) -> object? and Object::toString.call( object ) is "[object Number]"
isNaN = (object) -> isNumber(object) and object isnt object
###
# class Observable
# ID = 0
# activeObserver = null
# id: null
# observers: null
# subscriptions: null
# getActiveObserver = ->
# return null unless observerStack.length > 0
# return observerStack[observerStack.length - 1]
# #END getActiveObserver
# constructor: (obj, prop, value) ->
# @id = ID++
# switch
# when isFunction(value) then @defineWithFunction(obj, prop, value)
# else @defineWithPrimitive(obj, prop, value)
# #END switch
# #END constructor
# defineWithPrimitive: (obj, prop, value) ->
# Object.defineProperty(obj, prop, {
# writable: true
# get: =>
# @bindToActiveObserver()
# return value
# #END get
# set: (v) =>
# return unless value isnt v
# value = v
# @notifySubscribedObservers()
# #END set
# })
# #END defineWithPrimitive
# defineWithFunction: (obj, prop, callback) ->
# Object.defineProperty(obj, prop, {
# writable: true
# get: =>
# @bindToActiveObserver()
# previousObserver = activeObserver
# activeObserver = @
# v = callback()
# activeObserver = previousObserver
# return value if v is value
# @notifySubscribedObservers()
# value = v
# return value
# #END get
# })
# #END defineWithFunction
# bindToActiveObserver: ->
# #END bindToActiveObserver
# notifySubscribedObservers: ->
# #END notifySubscribedObservers
# subscribe: (callback)...