2015-11-19 12:47:11 +00:00
|
|
|
{EventEmitter} = require 'events'
|
|
|
|
|
|
|
|
bindings = process.atomBinding 'session'
|
|
|
|
|
|
|
|
PERSIST_PERFIX = 'persist:'
|
|
|
|
|
2015-11-19 13:03:42 +00:00
|
|
|
# Returns the Session from |partition| string.
|
2015-11-19 12:47:11 +00:00
|
|
|
exports.fromPartition = (partition='') ->
|
2015-12-12 07:47:15 +00:00
|
|
|
return exports.defaultSession if partition is ''
|
2015-11-19 12:47:11 +00:00
|
|
|
if partition.startsWith PERSIST_PERFIX
|
|
|
|
bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
|
|
|
|
else
|
|
|
|
bindings.fromPartition partition, true
|
|
|
|
|
2015-11-19 13:03:42 +00:00
|
|
|
# Returns the default session.
|
|
|
|
Object.defineProperty exports, 'defaultSession',
|
|
|
|
enumerable: true
|
2015-12-12 07:47:15 +00:00
|
|
|
get: -> bindings.fromPartition '', false
|
2015-11-19 13:03:42 +00:00
|
|
|
|
2015-11-19 12:47:11 +00:00
|
|
|
wrapSession = (session) ->
|
|
|
|
# session is an EventEmitter.
|
|
|
|
session.__proto__ = EventEmitter.prototype
|
|
|
|
|
|
|
|
bindings._setWrapSession wrapSession
|