Skip to content

Commit b9a72eb

Browse files
authored
Merge pull request #314 from share/after-write
Rename `afterSubmit` middleware hook to `afterWrite`
2 parents f01cf0e + 52e94ba commit b9a72eb

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Register a new middleware.
152152
before being committed to the database
153153
* `'commit'`: An operation was applied to a snapshot; The operation
154154
and new snapshot are about to be written to the database.
155-
* `'afterSubmit'`: An operation was successfully submitted to
155+
* `'afterWrite'`: An operation was successfully written to
156156
the database.
157157
* `'receive'`: Received a message from a client
158158
* `'reply'`: About to send a non-error reply to a client message
@@ -321,7 +321,7 @@ Populate the fields on `doc` with a snapshot of the document from the server.
321321
Populate the fields on `doc` with a snapshot of the document from the server, and
322322
fire events on subsequent changes.
323323

324-
`doc.unsubscribe(function (err) {...})`
324+
`doc.unsubscribe(function (err) {...})`
325325
Stop listening for document updates. The document data at the time of unsubscribing remains in memory, but no longer stays up-to-date. Resubscribe with `doc.subscribe`.
326326

327327
`doc.ingestSnapshot(snapshot, callback)`

lib/backend.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var warnDeprecatedAfterSubmit = true;
1818
var DOC_ACTION_DEPRECATION_WARNING = 'DEPRECATED: "doc" middleware action. Use "readSnapshots" instead. ' +
1919
'Pass `disableDocAction: true` option to ShareDB to disable the "doc" action and this warning.';
2020

21-
var AFFTER_SUBMIT_ACTION_DEPRECATION_WARNING = 'DEPRECATED: "after submit" middleware action. ' +
22-
'Use "afterSubmit" instead. Pass `disableSpaceDelimitedActions: true` option to ShareDB to ' +
23-
'disable the "after submit" action and this warning.';
21+
var AFTER_SUBMIT_ACTION_DEPRECATION_WARNING = 'DEPRECATED: "after submit" and "afterSubmit" middleware actions. ' +
22+
'Use "afterWrite" instead. Pass `disableSpaceDelimitedActions: true` option to ShareDB to ' +
23+
'disable the "after submit" and "afterSubmit" actions and this warning.';
2424

2525
function Backend(options) {
2626
if (!(this instanceof Backend)) return new Backend(options);
@@ -59,10 +59,12 @@ module.exports = Backend;
5959
emitter.mixin(Backend);
6060

6161
Backend.prototype.MIDDLEWARE_ACTIONS = {
62-
// An operation was successfully submitted to the database.
62+
// DEPRECATED: Synonym for 'afterWrite'
6363
afterSubmit: 'afterSubmit',
64-
// DEPRECATED: Synonym for 'afterSubmit'
64+
// DEPRECATED: Synonym for 'afterWrite'
6565
'after submit': 'after submit',
66+
// An operation was successfully written to the database.
67+
afterWrite: 'afterWrite',
6668
// An operation is about to be applied to a snapshot before being committed to the database
6769
apply: 'apply',
6870
// An operation was applied to a snapshot; The operation and new snapshot are about to be written to the database.
@@ -114,17 +116,20 @@ Backend.prototype._shimDocAction = function() {
114116
};
115117

116118
// Shim for backwards compatibility with deprecated middleware action name.
117-
// The action 'after submit' is now 'afterSubmit'.
119+
// The actions 'after submit' and 'afterSubmit' are now 'afterWrite'.
118120
Backend.prototype._shimAfterSubmit = function() {
119121
if (warnDeprecatedAfterSubmit) {
120122
warnDeprecatedAfterSubmit = false;
121-
console.warn(AFFTER_SUBMIT_ACTION_DEPRECATION_WARNING);
123+
console.warn(AFTER_SUBMIT_ACTION_DEPRECATION_WARNING);
122124
}
123125

124126
var backend = this;
125-
this.use(backend.MIDDLEWARE_ACTIONS.afterSubmit, function(request, callback) {
127+
this.use(backend.MIDDLEWARE_ACTIONS.afterWrite, function(request, callback) {
126128
backend.trigger(backend.MIDDLEWARE_ACTIONS['after submit'], request.agent, request, callback);
127129
});
130+
this.use(backend.MIDDLEWARE_ACTIONS.afterWrite, function(request, callback) {
131+
backend.trigger(backend.MIDDLEWARE_ACTIONS['afterSubmit'], request.agent, request, callback);
132+
});
128133
};
129134

130135
Backend.prototype.close = function(callback) {
@@ -251,7 +256,7 @@ Backend.prototype.submit = function(agent, index, id, op, options, callback) {
251256
if (err) return callback(err);
252257
request.submit(function(err) {
253258
if (err) return callback(err);
254-
backend.trigger(backend.MIDDLEWARE_ACTIONS.afterSubmit, agent, request, function(err) {
259+
backend.trigger(backend.MIDDLEWARE_ACTIONS.afterWrite, agent, request, function(err) {
255260
if (err) return callback(err);
256261
backend._sanitizeOps(agent, request.projection, request.collection, id, request.ops, function(err) {
257262
if (err) return callback(err);

test/middleware.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ describe('middleware', function() {
283283
});
284284

285285
describe('submit lifecycle', function() {
286-
// DEPRECATED: 'after submit' is a synonym for 'afterSubmit'
287-
['submit', 'apply', 'commit', 'afterSubmit', 'after submit'].forEach(function(action) {
286+
// DEPRECATED: 'after submit' and 'afterSubmit' are synonyms for 'afterWrite'
287+
['submit', 'apply', 'commit', 'afterWrite', 'afterSubmit', 'after submit'].forEach(function(action) {
288288
it(action + ' gets options passed to backend.submit', function(done) {
289289
var doneAfter = util.callAfter(1, done);
290290
this.backend.use(action, function(request, next) {

0 commit comments

Comments
 (0)