mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-28 15:27:43 +00:00
Add post-modifier stuff to Apollo. Add convenience methods to FineWrapper for dealing with things that are expected to only have one instance at any given time.
This commit is contained in:
parent
127184f997
commit
b51306019a
2 changed files with 31 additions and 5 deletions
|
@ -6,7 +6,7 @@
|
|||
// ============================================================================
|
||||
|
||||
import Module from 'utilities/module';
|
||||
import {has, get} from 'utilities/object';
|
||||
import {has, get, deep_copy} from 'utilities/object';
|
||||
|
||||
export default class Apollo extends Module {
|
||||
constructor(...args) {
|
||||
|
@ -27,6 +27,15 @@ export default class Apollo extends Module {
|
|||
}
|
||||
}`);
|
||||
|
||||
this.registerModifier('ChannelPage_ChannelInfoBar_User', data => {
|
||||
const u = data && data.data && data.data.user;
|
||||
if ( u ) {
|
||||
const o = u.profileViewCount = new Number(u.profileViewCount || 0);
|
||||
o.data = deep_copy(u);
|
||||
}
|
||||
}, false);
|
||||
|
||||
|
||||
this.registerModifier('FollowedIndex_CurrentUser', `query {
|
||||
currentUser {
|
||||
followedLiveUsers {
|
||||
|
@ -218,8 +227,11 @@ export default class Apollo extends Module {
|
|||
}
|
||||
|
||||
|
||||
registerModifier(operation, modifier) {
|
||||
registerModifier(operation, modifier, pre=true) {
|
||||
if ( typeof modifier !== 'function' ) {
|
||||
if ( ! pre )
|
||||
throw new Error('post modifiers must be functions');
|
||||
|
||||
let parsed;
|
||||
try {
|
||||
parsed = this.graphql ? this.graphql.parse(modifier, {noLocation: true}) : null;
|
||||
|
@ -231,15 +243,21 @@ export default class Apollo extends Module {
|
|||
modifier = [modifier, parsed];
|
||||
}
|
||||
|
||||
const mods = this.modifiers[operation] = this.modifiers[operation] || [];
|
||||
const mods = pre ?
|
||||
(this.modifiers[operation] = this.modifiers[operation] || []) :
|
||||
(this.post_modifiers[operation] = this.post_modifiers[operation] || []);
|
||||
|
||||
mods.push(modifier);
|
||||
}
|
||||
|
||||
unregisterModifier(operation, modifier) {
|
||||
const mods = this.modifiers[operation];
|
||||
unregisterModifier(operation, modifier, pre=true) {
|
||||
const mods = pre ? this.modifiers[operation] : this.post_modifiers[operation];
|
||||
if ( ! mods )
|
||||
return;
|
||||
|
||||
if ( typeof modifier !== 'function' )
|
||||
throw new Error('graphql modifiers cannot be removed');
|
||||
|
||||
for(let i=0; i < mods.length; i++) {
|
||||
const mod = mods[i];
|
||||
if ( typeof mod === 'function' ? mod === modifier : mod[0] === modifier ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue