pushing small changes

This commit is contained in:
Jean Ouina 2020-08-10 18:52:47 +02:00
parent 25e465ac05
commit 84578b1153
4 changed files with 202 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,7 @@ import { isNative, isImported } from "./modules/environnement"
import * as bandagedbdApi from "@bandagedbd/bdapi" import * as bandagedbdApi from "@bandagedbd/bdapi"
import "./alias/react" import "./alias/react"
import "./alias/react-dom" import "./alias/react-dom"
import { LazyLoad } from "./modules/lazyLoader"
patchers.patch() patchers.patch()
const LightcordApi = { const LightcordApi = {
@ -27,7 +28,8 @@ const LightcordApi = {
unfreeze: unfreeze unfreeze: unfreeze
}, },
get isNative(){return isNative}, get isNative(){return isNative},
get isImported(){return isImported} get isImported(){return isImported},
LazyLoad: LazyLoad
} }
declare global { declare global {

View File

@ -0,0 +1,84 @@
let cache = new Map()
export function LazyLoad<T>(getObject: () => T):T{
if(cache.has(getObject))return cache.get(getObject)
let mdl = null
let setModule = () => {
if(mdl)return
mdl = getObject()
}
let handler:ProxyHandler<{}> = {
get(target, prop){
setModule()
return mdl[prop]
},
set(target, prop, value){
setModule()
mdl[prop] = value
return true
},
apply(target, thisArg, args){
setModule()
mdl.apply(this, args)
},
construct(target, args){
setModule()
const prototype = Object.create(mdl.prototype)
handler.apply(target, prototype, args)
return prototype
},
deleteProperty(target, prop){
setModule()
if(!(prop in mdl))return false
delete mdl[prop]
return true
},
enumerate(target){
setModule()
return Object.keys(mdl)
},
ownKeys(target) {
setModule()
return Object.keys(mdl)
},
has(target, prop){
setModule()
return prop in mdl
},
defineProperty(target, prop, attributes){
setModule()
return Object.defineProperty(mdl, prop, attributes)
},
getOwnPropertyDescriptor(target, prop){
setModule()
return Object.getOwnPropertyDescriptor(mdl, prop)
},
getPrototypeOf(target){
setModule()
return Object.getPrototypeOf(mdl)
},
setPrototypeOf(target, proto){
setModule()
try{
Object.setPrototypeOf(mdl, proto)
return true
}catch(e){
return false
}
},
isExtensible(target){
setModule()
return Object.isExtensible(mdl)
},
preventExtensions(target){
setModule()
Object.preventExtensions(mdl)
return true
}
}
const proxy = new Proxy({}, handler)
cache.set(getObject, proxy)
return proxy as T
}

10
todolist.md Normal file
View File

@ -0,0 +1,10 @@
# Todo list
Yes, this list is here because I can't remember what to do when I have the time.
- [x] Fixing #11
- [x] Fixing #10
- [ ] Transition from WebViews to BrowserView in tabs
- [x] lightcord-9 setting.
- [x] Fixing #14
- [ ] Fixing #15
- [x] LazyLoader in LightcordApi.