mirror of
https://github.com/HackPlan/atom-shell.git
synced 2026-06-18 03:48:12 +08:00
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.
23 lines
578 B
CoffeeScript
23 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]
|