Merge branch 'immediate-finds' into immediate-finds-modules-proxy
This commit is contained in:
commit
72b014fe67
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vencord",
|
"name": "vencord",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"version": "1.8.5",
|
"version": "1.8.6",
|
||||||
"description": "The cutest Discord client mod",
|
"description": "The cutest Discord client mod",
|
||||||
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default definePlugin({
|
||||||
find: '"NoticeStore"',
|
find: '"NoticeStore"',
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /\i=null;(?=.{0,80}getPremiumSubscription\(\))/g,
|
match: /(?<=!1;)\i=null;(?=.{0,80}getPremiumSubscription\(\))/g,
|
||||||
replace: "if(Vencord.Api.Notices.currentNotice)return false;$&"
|
replace: "if(Vencord.Api.Notices.currentNotice)return false;$&"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,6 +56,26 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
// Discord Stable
|
||||||
|
// FIXME: remove once change merged to stable
|
||||||
|
{
|
||||||
|
find: "Messages.ACTIVITY_SETTINGS",
|
||||||
|
replacement: {
|
||||||
|
get match() {
|
||||||
|
switch (Settings.plugins.Settings.settingsLocation) {
|
||||||
|
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS/;
|
||||||
|
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS/;
|
||||||
|
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS/;
|
||||||
|
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/;
|
||||||
|
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/;
|
||||||
|
case "aboveActivity":
|
||||||
|
default:
|
||||||
|
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS/;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
replace: "...$self.makeSettingsCategories($1),$&"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
find: "Messages.ACTIVITY_SETTINGS",
|
find: "Messages.ACTIVITY_SETTINGS",
|
||||||
replacement: {
|
replacement: {
|
||||||
|
|
|
@ -31,10 +31,10 @@ export default definePlugin({
|
||||||
// Some modules match the find but the replacement is returned untouched
|
// Some modules match the find but the replacement is returned untouched
|
||||||
noWarn: true,
|
noWarn: true,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /canAnimate:.+?(?=([,}].*?\)))/g,
|
match: /canAnimate:.+?([,}].*?\))/g,
|
||||||
replace: (m, rest) => {
|
replace: (m, rest) => {
|
||||||
const destructuringMatch = rest.match(/}=.+/);
|
const destructuringMatch = rest.match(/}=.+/);
|
||||||
if (destructuringMatch == null) return "canAnimate:!0";
|
if (destructuringMatch == null) return `canAnimate:!0${rest}`;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,8 +112,8 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
// Create the isBetterFolders variable in the GuildsBar component
|
// Create the isBetterFolders variable in the GuildsBar component
|
||||||
{
|
{
|
||||||
match: /(?<=let{disableAppDownload:\i=\i\.isPlatformEmbedded,isOverlay:.+?)(?=}=\i,)/,
|
match: /let{disableAppDownload:\i=\i\.isPlatformEmbedded,isOverlay:.+?(?=}=\i,)/,
|
||||||
replace: ",isBetterFolders"
|
replace: "$&,isBetterFolders"
|
||||||
},
|
},
|
||||||
// If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders
|
// If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,8 +112,8 @@ export default definePlugin({
|
||||||
{ // Load menu TOC eagerly
|
{ // Load menu TOC eagerly
|
||||||
find: "Messages.USER_SETTINGS_WITH_BUILD_OVERRIDE.format",
|
find: "Messages.USER_SETTINGS_WITH_BUILD_OVERRIDE.format",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=(\i)\(this,"handleOpenSettingsContextMenu",.{0,100}?openContextMenuLazy.{0,100}?(await Promise\.all[^};]*?\)\)).*?,)(?=\1\(this)/,
|
match: /(\i)\(this,"handleOpenSettingsContextMenu",.{0,100}?openContextMenuLazy.{0,100}?(await Promise\.all[^};]*?\)\)).*?,(?=\1\(this)/,
|
||||||
replace: "(async ()=>$2)(),"
|
replace: "$&(async ()=>$2)(),"
|
||||||
},
|
},
|
||||||
predicate: () => settings.store.eagerLoad
|
predicate: () => settings.store.eagerLoad
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,9 +34,9 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".AVATAR_STATUS_MOBILE_16;",
|
find: ".AVATAR_STATUS_MOBILE_16;",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=fromIsMobile:\i=!0,.+?)status:(\i)/,
|
match: /(fromIsMobile:\i=!0,.+?)status:(\i)/,
|
||||||
// Rename field to force it to always use "online"
|
// Rename field to force it to always use "online"
|
||||||
replace: 'status_$:$1="online"'
|
replace: '$1status_$:$2="online"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -343,8 +343,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
// Patch the stickers array to add fake nitro stickers
|
// Patch the stickers array to add fake nitro stickers
|
||||||
predicate: () => settings.store.transformStickers,
|
predicate: () => settings.store.transformStickers,
|
||||||
match: /(?<=renderStickersAccessories\((\i)\){let (\i)=\(0,\i\.\i\)\(\i\).+?;)/,
|
match: /renderStickersAccessories\((\i)\){let (\i)=\(0,\i\.\i\)\(\i\).+?;/,
|
||||||
replace: (_, message, stickers) => `${stickers}=$self.patchFakeNitroStickers(${stickers},${message});`
|
replace: (m, message, stickers) => `${m}${stickers}=$self.patchFakeNitroStickers(${stickers},${message});`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Filter attachments to remove fake nitro stickers or emojis
|
// Filter attachments to remove fake nitro stickers or emojis
|
||||||
|
|
|
@ -228,15 +228,15 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".activityTitleText,variant",
|
find: ".activityTitleText,variant",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=\i\.activityTitleText.+?children:(\i)\.name.*?}\),)/,
|
match: /\.activityTitleText.+?children:(\i)\.name.*?}\),/,
|
||||||
replace: (_, props) => `$self.renderToggleActivityButton(${props}),`
|
replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: ".activityCardDetails,children",
|
find: ".activityCardDetails,children",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=\i\.activityCardDetails.+?children:(\i\.application)\.name.*?}\),)/,
|
match: /\.activityCardDetails.+?children:(\i\.application)\.name.*?}\),/,
|
||||||
replace: (_, props) => `$self.renderToggleActivityButton(${props}),`
|
replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -70,8 +70,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".invitesDisabledTooltip",
|
find: ".invitesDisabledTooltip",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=\.VIEW_AS_ROLES_MENTIONS_WARNING.{0,100})]/,
|
match: /\.VIEW_AS_ROLES_MENTIONS_WARNING.{0,100}(?=])/,
|
||||||
replace: ",$self.renderTooltip(arguments[0].guild)]"
|
replace: "$&,$self.renderTooltip(arguments[0].guild)"
|
||||||
},
|
},
|
||||||
predicate: () => settings.store.toolTip
|
predicate: () => settings.store.toolTip
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,8 +111,8 @@ export default definePlugin({
|
||||||
replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)"
|
replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /(?<=scrollToChannel\(\i\){.{1,300})this\.props\.privateChannelIds/,
|
match: /(scrollToChannel\(\i\){.{1,300})(this\.props\.privateChannelIds)/,
|
||||||
replace: "[...$&,...$self.getAllUncollapsedChannels()]"
|
replace: "$1[...$2,...$self.getAllUncollapsedChannels()]"
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -134,8 +134,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: '"MessageActionCreators"',
|
find: '"MessageActionCreators"',
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=focusMessage\(\i\){.+?)(?=focus:{messageId:(\i)})/,
|
match: /focusMessage\(\i\){.+?(?=focus:{messageId:(\i)})/,
|
||||||
replace: "after:$1,"
|
replace: "$&after:$1,"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Force Server Home instead of Server Guide
|
// Force Server Home instead of Server Guide
|
||||||
|
|
|
@ -89,8 +89,8 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
// Remove permission checking for getRenderLevel function
|
// Remove permission checking for getRenderLevel function
|
||||||
{
|
{
|
||||||
match: /(?<=getRenderLevel\(\i\){.+?return)!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,this\.record\)\|\|/,
|
match: /(getRenderLevel\(\i\){.+?return)!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,this\.record\)\|\|/,
|
||||||
replace: " "
|
replace: (_, rest) => `${rest} `
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -159,8 +159,8 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
// Make the channel appear as muted if it's hidden
|
// Make the channel appear as muted if it's hidden
|
||||||
{
|
{
|
||||||
match: /(?<={channel:(\i),name:\i,muted:(\i).+?;)/,
|
match: /{channel:(\i),name:\i,muted:(\i).+?;/,
|
||||||
replace: (_, channel, muted) => `${muted}=$self.isHiddenChannel(${channel})?true:${muted};`
|
replace: (m, channel, muted) => `${m}${muted}=$self.isHiddenChannel(${channel})?true:${muted};`
|
||||||
},
|
},
|
||||||
// Add the hidden eye icon if the channel is hidden
|
// Add the hidden eye icon if the channel is hidden
|
||||||
{
|
{
|
||||||
|
@ -186,8 +186,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
// Hide unreads
|
// Hide unreads
|
||||||
predicate: () => settings.store.hideUnreads === true,
|
predicate: () => settings.store.hideUnreads === true,
|
||||||
match: /(?<={channel:(\i),name:\i,.+?unread:(\i).+?;)/,
|
match: /{channel:(\i),name:\i,.+?unread:(\i).+?;/,
|
||||||
replace: (_, channel, unread) => `${unread}=$self.isHiddenChannel(${channel})?false:${unread};`
|
replace: (m, channel, unread) => `${m}${unread}=$self.isHiddenChannel(${channel})?false:${unread};`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -60,8 +60,8 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicate: () => settings.store.keepSpotifyActivityOnIdle,
|
predicate: () => settings.store.keepSpotifyActivityOnIdle,
|
||||||
match: /(?<=shouldShowActivity\(\){.{0,50})&&!\i\.\i\.isIdle\(\)/,
|
match: /(shouldShowActivity\(\){.{0,50})&&!\i\.\i\.isIdle\(\)/,
|
||||||
replace: ""
|
replace: "$1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ",BURST_REACTION_EFFECT_PLAY",
|
find: ",BURST_REACTION_EFFECT_PLAY",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=BURST_REACTION_EFFECT_PLAY:\i=>{.{50,100})(\i\(\i,\i\))>=\d+/,
|
match: /(BURST_REACTION_EFFECT_PLAY:\i=>{.{50,100})(\i\(\i,\i\))>=\d+/,
|
||||||
replace: "!$self.shouldPlayBurstReaction($1)"
|
replace: "$1!$self.shouldPlayBurstReaction($2)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -206,8 +206,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".avatarPositionPanel",
|
find: ".avatarPositionPanel",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/,
|
match: /(avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/,
|
||||||
replace: "style:($1)?{cursor:\"pointer\"}:{},onClick:$1?()=>{$self.openImage($2)}"
|
replace: "$1style:($2)?{cursor:\"pointer\"}:{},onClick:$2?()=>{$self.openImage($3)}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Group DMs top small & large icon
|
// Group DMs top small & large icon
|
||||||
|
|
|
@ -40,6 +40,10 @@ const handler: ProxyHandler<any> = {
|
||||||
...Object.fromEntries(Object.getOwnPropertyNames(Reflect).map(propName =>
|
...Object.fromEntries(Object.getOwnPropertyNames(Reflect).map(propName =>
|
||||||
[propName, (target: any, ...args: any[]) => Reflect[propName](target[proxyLazyGet](), ...args)]
|
[propName, (target: any, ...args: any[]) => Reflect[propName](target[proxyLazyGet](), ...args)]
|
||||||
)),
|
)),
|
||||||
|
set: (target, p, newValue) => {
|
||||||
|
const lazyTarget = target[proxyLazyGet]();
|
||||||
|
return Reflect.set(lazyTarget, p, newValue, lazyTarget);
|
||||||
|
},
|
||||||
ownKeys: target => {
|
ownKeys: target => {
|
||||||
const keys = Reflect.ownKeys(target[proxyLazyGet]());
|
const keys = Reflect.ownKeys(target[proxyLazyGet]());
|
||||||
for (const key of UNCONFIGURABLE_PROPERTIES) {
|
for (const key of UNCONFIGURABLE_PROPERTIES) {
|
||||||
|
@ -70,7 +74,9 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
|
||||||
let isSameTick = true;
|
let isSameTick = true;
|
||||||
if (!isChild) setTimeout(() => isSameTick = false, 0);
|
if (!isChild) setTimeout(() => isSameTick = false, 0);
|
||||||
|
|
||||||
const proxyDummy = Object.assign(function ProxyDummy() { }, {
|
// Define the function in an object to preserve the name after minification
|
||||||
|
const proxyDummy = ({ ProxyDummy() { } }).ProxyDummy;
|
||||||
|
Object.assign(proxyDummy, {
|
||||||
[proxyLazyGet]() {
|
[proxyLazyGet]() {
|
||||||
if (!proxyDummy[proxyLazyCache]) {
|
if (!proxyDummy[proxyLazyCache]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -80,6 +86,10 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
|
||||||
|
|
||||||
if (!proxyDummy[proxyLazyCache]) {
|
if (!proxyDummy[proxyLazyCache]) {
|
||||||
throw new Error(`proxyLazy factory failed:\n\n${factory}`);
|
throw new Error(`proxyLazy factory failed:\n\n${factory}`);
|
||||||
|
} else {
|
||||||
|
if (typeof proxyDummy[proxyLazyCache] === "function") {
|
||||||
|
proxy.toString = proxyDummy[proxyLazyCache].toString.bind(proxyDummy[proxyLazyCache]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +98,9 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
|
||||||
[proxyLazyCache]: void 0 as T | undefined
|
[proxyLazyCache]: void 0 as T | undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Proxy(proxyDummy, {
|
const proxy = new Proxy(proxyDummy, {
|
||||||
...handler,
|
...handler,
|
||||||
get(target, p, receiver) {
|
get(target, p) {
|
||||||
if (p === proxyLazyGet) return target[proxyLazyGet];
|
if (p === proxyLazyGet) return target[proxyLazyGet];
|
||||||
if (p === proxyLazyCache) return target[proxyLazyCache];
|
if (p === proxyLazyCache) return target[proxyLazyCache];
|
||||||
|
|
||||||
|
@ -100,7 +110,7 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
|
||||||
// `const { meow } = proxyLazy(() => ({ meow: [] }));`
|
// `const { meow } = proxyLazy(() => ({ meow: [] }));`
|
||||||
if (!isChild && isSameTick) {
|
if (!isChild && isSameTick) {
|
||||||
return proxyLazy(
|
return proxyLazy(
|
||||||
() => Reflect.get(target[proxyLazyGet](), p, receiver),
|
() => Reflect.get(target[proxyLazyGet](), p, target[proxyLazyGet]()),
|
||||||
attempts,
|
attempts,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -108,10 +118,12 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
|
||||||
|
|
||||||
const lazyTarget = target[proxyLazyGet]();
|
const lazyTarget = target[proxyLazyGet]();
|
||||||
if (typeof lazyTarget === "object" || typeof lazyTarget === "function") {
|
if (typeof lazyTarget === "object" || typeof lazyTarget === "function") {
|
||||||
return Reflect.get(lazyTarget, p, receiver);
|
return Reflect.get(lazyTarget, p, lazyTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("proxyLazy called on a primitive value. This can happen if you try to destructure a primitive at the same tick as the proxy was created.");
|
throw new Error("proxyLazy called on a primitive value. This can happen if you try to destructure a primitive at the same tick as the proxy was created.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ const handler: ProxyHandler<any> = {
|
||||||
...Object.fromEntries(Object.getOwnPropertyNames(Reflect).map(propName =>
|
...Object.fromEntries(Object.getOwnPropertyNames(Reflect).map(propName =>
|
||||||
[propName, (target: any, ...args: any[]) => Reflect[propName](target[proxyInnerGet](), ...args)]
|
[propName, (target: any, ...args: any[]) => Reflect[propName](target[proxyInnerGet](), ...args)]
|
||||||
)),
|
)),
|
||||||
|
set: (target, p, value) => {
|
||||||
|
const innerTarget = target[proxyInnerGet]();
|
||||||
|
return Reflect.set(innerTarget, p, value, innerTarget);
|
||||||
|
},
|
||||||
ownKeys: target => {
|
ownKeys: target => {
|
||||||
const keys = Reflect.ownKeys(target[proxyInnerGet]());
|
const keys = Reflect.ownKeys(target[proxyInnerGet]());
|
||||||
for (const key of UNCONFIGURABLE_PROPERTIES) {
|
for (const key of UNCONFIGURABLE_PROPERTIES) {
|
||||||
|
@ -51,7 +55,9 @@ export function proxyInner<T = AnyObject>(
|
||||||
let isSameTick = true;
|
let isSameTick = true;
|
||||||
if (!isChild) setTimeout(() => isSameTick = false, 0);
|
if (!isChild) setTimeout(() => isSameTick = false, 0);
|
||||||
|
|
||||||
const proxyDummy = Object.assign(function ProxyDummy() { }, {
|
// Define the function in an object to preserve the name after minification
|
||||||
|
const proxyDummy = ({ ProxyDummy() { } }).ProxyDummy;
|
||||||
|
Object.assign(proxyDummy, {
|
||||||
[proxyInnerGet]: function () {
|
[proxyInnerGet]: function () {
|
||||||
if (proxyDummy[proxyInnerValue] == null) {
|
if (proxyDummy[proxyInnerValue] == null) {
|
||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
|
@ -62,19 +68,9 @@ export function proxyInner<T = AnyObject>(
|
||||||
[proxyInnerValue]: void 0 as T | undefined
|
[proxyInnerValue]: void 0 as T | undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
// Values destructured in the same tick the proxy was created will push their setInnerValue here
|
const proxy = new Proxy(proxyDummy, {
|
||||||
const recursiveSetInnerValues = [] as Array<(innerValue: T) => void>;
|
|
||||||
|
|
||||||
// Once we set the parent inner value, we will call the setInnerValue functions of the destructured values,
|
|
||||||
// for them to get the proper value from the parent and use as their inner instead
|
|
||||||
function setInnerValue(innerValue: T) {
|
|
||||||
proxyDummy[proxyInnerValue] = innerValue;
|
|
||||||
recursiveSetInnerValues.forEach(setInnerValue => setInnerValue(innerValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
return [new Proxy(proxyDummy, {
|
|
||||||
...handler,
|
...handler,
|
||||||
get(target, p, receiver) {
|
get(target, p) {
|
||||||
if (p === proxyInnerValue) return target[proxyInnerValue];
|
if (p === proxyInnerValue) return target[proxyInnerValue];
|
||||||
if (p === proxyInnerGet) return target[proxyInnerGet];
|
if (p === proxyInnerGet) return target[proxyInnerGet];
|
||||||
|
|
||||||
|
@ -87,7 +83,7 @@ export function proxyInner<T = AnyObject>(
|
||||||
|
|
||||||
recursiveSetInnerValues.push((innerValue: T) => {
|
recursiveSetInnerValues.push((innerValue: T) => {
|
||||||
// Set the inner value of the destructured value as the prop value p of the parent
|
// Set the inner value of the destructured value as the prop value p of the parent
|
||||||
recursiveSetInnerValue(Reflect.get(innerValue as object, p, receiver));
|
recursiveSetInnerValue(Reflect.get(innerValue as object, p, innerValue));
|
||||||
});
|
});
|
||||||
|
|
||||||
return recursiveProxy;
|
return recursiveProxy;
|
||||||
|
@ -95,11 +91,26 @@ export function proxyInner<T = AnyObject>(
|
||||||
|
|
||||||
const innerTarget = target[proxyInnerGet]();
|
const innerTarget = target[proxyInnerGet]();
|
||||||
if (typeof innerTarget === "object" || typeof innerTarget === "function") {
|
if (typeof innerTarget === "object" || typeof innerTarget === "function") {
|
||||||
return Reflect.get(innerTarget, p, receiver);
|
return Reflect.get(innerTarget, p, innerTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(primitiveErrMsg);
|
throw new Error(primitiveErrMsg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Values destructured in the same tick the proxy was created will push their setInnerValue here
|
||||||
|
const recursiveSetInnerValues = [] as Array<(innerValue: T) => void>;
|
||||||
|
|
||||||
|
// Once we set the parent inner value, we will call the setInnerValue functions of the destructured values,
|
||||||
|
// for them to get the proper value from the parent and use as their inner instead
|
||||||
|
function setInnerValue(innerValue: T) {
|
||||||
|
proxyDummy[proxyInnerValue] = innerValue;
|
||||||
|
recursiveSetInnerValues.forEach(setInnerValue => setInnerValue(innerValue));
|
||||||
|
|
||||||
|
if (typeof innerValue === "function") {
|
||||||
|
proxy.toString = innerValue.toString.bind(innerValue);
|
||||||
}
|
}
|
||||||
}), setInnerValue];
|
}
|
||||||
|
|
||||||
|
return [proxy, setInnerValue];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue