а может как-то так? (псевдокод)

    
```coffee
    namespace 'uploadcare.dialog', (ns) ->

        currentDialog = null
        ownerCount = 0

        ns.acquireDialog = ->
            # returns a Dialog instance
            # which can be used to access its DOM and stuff
            # while the dialog is acquired it is shown

            currentDialog = new Dialog() if not currentDialog

            owners += 1

            currentDialog.__show()

            return currentDialog

        checkAndClose = ->
            if not owners
                currentDialog.__hide()

        class Dialog
            __hide: ->
            __show: ->
            release: ->
                # releases a dialog
                # it's closed if it's not needed by anyone else

                owners -= 1
                setTimeout -> checkAndClose(), 100
```

тогда использовать можно как-то так:

```coffee

someFunctionWhichShowsSelectDialog = ->
    dialog = uploadcare.dialog.acquireDialog()

    useDialogForSelection dialog

    whenFileSelected (file_id) ->
        someFunctionWhichShowsCropDialog file_id
        dialog.release()


someFunctionWhichShowsCropDialog (file_id) = ->
    dialog = uploadcare.dialog.acquireDialog()

    useDialogForCrop dialog

    whenCropSelected ->
        dialog.release()

```