Skip to content

Commit

Permalink
store methods wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Sep 19, 2023
1 parent 9f51ec2 commit dbefe8e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ function hasZeroSubscribersBug() {
}
module.exports.hasZeroSubscribersBug = hasZeroSubscribersBug;

function hasChannelStoreMethods() {
return hasFullSupport()
|| (MAJOR === 19 && MINOR >= 9);
}
module.exports.hasChannelStoreMethods = hasChannelStoreMethods;

// if Channel#unsubscribe() returns a boolean
function hasChUnsubscribeReturn() {
return (MAJOR >= 18) // 18.0, 19.0, etc.
Expand Down
4 changes: 4 additions & 0 deletions dc-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ if (!checks.hasChUnsubscribeReturn()) {
require('./patch-channel-unsubscribe-return.js')(dc);
}

if (!checks.hasChannelStoreMethods()) {
require('./patch-channel-store-methods.js')(dc);
}

if (!checks.hasTracingChannel()) {
require('./patch-tracing-channel.js')(dc);
}
Expand Down
25 changes: 25 additions & 0 deletions patch-channel-store-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = function (dc) {
const channels = new WeakSet();

const dc_channel = dc.channel;

dc.channel = function() {
const ch = dc_channel.apply(this, arguments);

if (channels.has(ch)) return ch;

ch.bindStore = function() {
// TODO
};

ch.unbindStore = function() {
// TODO
};

ch.runStores = function() {
// TODO
};

return ch;
};
};
2 changes: 1 addition & 1 deletion patch-channel-unsubscribe-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ module.exports = function (dc) {
channels.add(ch);

return ch;
}
};
};
4 changes: 2 additions & 2 deletions patch-zero-subscriber-bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = function (dc) {
}

channels.add(ch);
}

return ch;
return ch;
}
};
3 changes: 3 additions & 0 deletions test/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ test('channel tests', t => {
t.ok(ch instanceof dc.Channel, 'dc.channel() return value instance of dc.Channel');
t.strictEqual(dc.channel('foo'), dc.channel('foo'), 'multiple calls to dc.channel() return same channel instance');
t.notEqual(dc.channel('foo'), dc.channel('bar'), 'calls to dc.channel() with different names return separate channel instances');
t.equal(typeof dc.channel('foo1').bindStore, 'function', 'provides Channel#bindStore()');
t.equal(typeof dc.channel('foo2').unbindStore, 'function', 'provides Channel#unbindStore()');
t.equal(typeof dc.channel('foo3').runStores, 'function', 'provides Channel#runStores()');
t.end();
});

Expand Down

0 comments on commit dbefe8e

Please sign in to comment.