electron/browser/atom/objects_registry.coffee
Cheng Zhao dded164052 Separate stored objects by the render view.
When a render view is closed, it's not guarrenteed that all objects'
weak callback would be called. So we must clean up all objects manually
after the render view gets closed.
2013-04-26 21:14:29 +08:00

22 lines
578 B
CoffeeScript

IDWeakMap = require 'id_weak_map'
globalStore = {}
globalMap = new IDWeakMap
getStoreForRenderView = (process_id, routing_id) ->
key = "#{process_id}_#{routing_id}"
globalStore[key] = {} unless globalStore[key]?
globalStore[key]
exports.add = (process_id, routing_id, obj) ->
id = globalMap.add obj
store = getStoreForRenderView process_id, routing_id
store[id] = obj
id
exports.get = (process_id, routing_id, id) ->
globalMap.get id
exports.remove = (process_id, routing_id, id) ->
store = getStoreForRenderView process_id, routing_id
delete store[id]