Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010226
event-manager.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
event-manager.js
View Options
const
Promise
=
require
(
"bluebird"
);
const
PatternEmitter
=
require
(
"pattern-emitter-promise"
).
EventEmitter
;
PatternEmitter
.
setPromiseLibrary
(
Promise
);
class
EventManager
{
constructor
(
app
)
{
app
.
ee
=
PatternEmitter
();
app
.
on
=
app
.
ee
.
on
.
bind
(
app
.
ee
);
app
.
off
=
app
.
ee
.
off
.
bind
(
app
.
ee
);
app
.
emit
=
app
.
ee
.
emit
.
bind
(
app
.
ee
);
app
.
removeAllListeners
=
app
.
ee
.
removeAllListeners
.
bind
(
app
.
ee
);
this
.
app
=
app
;
}
// TODO: this function is a symptom of leaking abstraction
// we need to abstract logic of intentions that base on secret tokens
subscribeToIntentionCreate
(
collection_name
,
template_name
)
{
this
.
subscribeTo
(
collection_name
,
"create"
,
"post"
,
async
(
context
,
path
,
params
,
intent
)
=>
{
const
token
=
(
await
this
.
app
.
run_action
(
new
this
.
app
.
Sealious
.
SuperContext
(),
[
"collections"
,
collection_name
,
intent
.
id
],
"show"
)).
body
.
token
;
const
message
=
await
this
.
app
.
MailTemplates
[
template_name
](
this
.
app
,
{
email_address
:
intent
.
body
.
email
,
token
,
}
);
return
message
.
send
(
this
.
app
);
}
);
}
subscribeTo
(
collection_pattern
,
action_name
,
when
,
callback
)
{
this
.
app
.
on
(
new
RegExp
(
`
${
when
}
:collections\.
${
collection_pattern
}
:
${
action_name
}
`
),
callback
);
}
}
module
.
exports
=
EventManager
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, May 7, 19:38 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
667361
Default Alt Text
event-manager.js (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment