yerel event
This commit is contained in:
parent
ce37dc6fc1
commit
087263d3f0
50
IndexedDB.ts
50
IndexedDB.ts
|
@ -26,7 +26,7 @@ class EventTarget
|
|||
{
|
||||
if(this._events.has(event))
|
||||
{
|
||||
this._events.get(event).push(callback)
|
||||
this._events.get(event)?.push(callback)
|
||||
}else{
|
||||
this._events.set(event,[callback])
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class EventTarget
|
|||
/**
|
||||
*
|
||||
* @param {string} type gerçekleşen olay türü
|
||||
* @param {...any[]} args olay gerçekleştiğinde çalışacak işlevler gönderilecek argümanlar
|
||||
* @param {...any[]} args olay gerexçekleştiğinde çalışacak işlevler gönderilecek argümanlar
|
||||
*/
|
||||
public emitEvent(type:string, ...args)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ export class IndexedDB extends EventTarget
|
|||
this.IsReady = false;
|
||||
this.DBRequest = IndexedDB.Engine.open(this.Model.name, this.Model.version || 0);
|
||||
this.DBRequest.addEventListener("upgradeneeded", this.executeMigrate.bind(this));
|
||||
new IEventLocate<IDBDatabase>(this.DBRequest).sync().then(async db => {
|
||||
new IEventLocate<IDBDatabase,IDBRequest>(this.DBRequest).sync().then(async db => {
|
||||
this.DB = db;
|
||||
this.IsReady = true;
|
||||
this.dispatchEvent(new Event("load"));
|
||||
|
@ -125,7 +125,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
objectStore = db.createObjectStore(e.name, {keyPath:e.key});
|
||||
}else{
|
||||
objectStore = this.DBRequest.transaction.objectStore(e.name);
|
||||
objectStore = (this.DBRequest.transaction as IDBTransaction).objectStore(e.name);
|
||||
}
|
||||
|
||||
e.columns.forEach(name => {
|
||||
|
@ -172,7 +172,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).add(data);
|
||||
return await (new IEventLocate<IDBValidKey>(store)).sync();
|
||||
return await (new IEventLocate<IDBValidKey,IDBRequest>(store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki tüm verileri temizler
|
||||
|
@ -181,7 +181,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).clear();
|
||||
return await (new IEventLocate<undefined>(store)).sync();
|
||||
return await (new IEventLocate<undefined,IDBRequest>(store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki verilerin sayısını döner
|
||||
|
@ -190,7 +190,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).count();
|
||||
return await (new IEventLocate<number>(store)).sync();
|
||||
return await (new IEventLocate<number,IDBRequest>(store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablo bir kayıt siler
|
||||
|
@ -199,25 +199,25 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).delete(name);
|
||||
return await (new IEventLocate <undefined> (store)).sync();
|
||||
return await (new IEventLocate <undefined,IDBRequest> (store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki bir kaydı okur
|
||||
* Tablodaki bir kaydı okur (primary key ile)
|
||||
*/
|
||||
public async get(tablename:string, index:string)
|
||||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).get(index);
|
||||
return await (new IEventLocate <{[key:string]:any}> (store)).sync();
|
||||
return await (new IEventLocate <any,IDBRequest> (store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki bir kaydı okur
|
||||
* Tablodaki bir kaydı okur (belirtilen index kolonuyla arar)
|
||||
*/
|
||||
public async getFrom(tablename:string, column:string, index:string)
|
||||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).index(column).get(index);
|
||||
return await (new IEventLocate <{[key:string]:any}> (store)).sync();
|
||||
return await (new IEventLocate <any,IDBRequest> (store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki tüm kayıtları alır
|
||||
|
@ -226,7 +226,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).getAll();
|
||||
return await (new IEventLocate <{[key:string]:any}[]> (store)).sync();
|
||||
return await (new IEventLocate <any[], IDBRequest> (store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tabloda veri yoksa oluşturur varsa günceller
|
||||
|
@ -249,7 +249,7 @@ export class IndexedDB extends EventTarget
|
|||
{
|
||||
if(!this.IsReady) return;
|
||||
let store = this.DB.transaction([tablename], "readwrite").objectStore(tablename).put(data);
|
||||
return await (new IEventLocate <IDBValidKey> (store)).sync();
|
||||
return await (new IEventLocate <IDBValidKey,IDBRequest> (store)).sync();
|
||||
}
|
||||
/**
|
||||
* Tablodaki tüm verileri tek tek verir
|
||||
|
@ -268,7 +268,7 @@ export class IndexedDB extends EventTarget
|
|||
try{
|
||||
callback(
|
||||
data,
|
||||
() => cursor.result.continue(),
|
||||
() => cursor.result?.continue(),
|
||||
() => ok(void 0),
|
||||
cursor.result.primaryKey
|
||||
)
|
||||
|
@ -372,27 +372,27 @@ export class IndexedDB extends EventTarget
|
|||
}
|
||||
if('mozIndexedDB' in window)
|
||||
{
|
||||
IndexedDB.Engine = window['mozIndexedDB']
|
||||
IndexedDB.Engine = window['mozIndexedDB'] as IDBFactory
|
||||
}
|
||||
if('webkitIndexedDB' in window)
|
||||
{
|
||||
IndexedDB.Engine = window['webkitIndexedDB']
|
||||
IndexedDB.Engine = window['webkitIndexedDB'] as IDBFactory
|
||||
}
|
||||
if('msIndexedDB' in window)
|
||||
{
|
||||
IndexedDB.Engine = window['msIndexedDB']
|
||||
IndexedDB.Engine = window['msIndexedDB'] as IDBFactory
|
||||
}
|
||||
}
|
||||
}
|
||||
interface ISheel{
|
||||
onsuccess : (e:any) => any;
|
||||
onerror : (e:any) => any;
|
||||
interface ISheel<Type>{
|
||||
onsuccess : ((this: Type, ev: Event) => any) | null;
|
||||
onerror : ((this: Type, ev: Event) => any) | null;
|
||||
}
|
||||
/**
|
||||
* Başarılı olduğunda onsuccess başarısız olduğunda onerror döndüren yapıları
|
||||
* javascript ES6 tarafında async/await yapısına dönüştürür böylece try-catch kullanılarak yakalanabilir
|
||||
*/
|
||||
class IEventLocate<Type>
|
||||
class IEventLocate<Type,Shell>
|
||||
{
|
||||
private result : {
|
||||
then:any[],
|
||||
|
@ -408,9 +408,9 @@ class IEventLocate<Type>
|
|||
catch: [],
|
||||
finally: []
|
||||
};
|
||||
public constructor(sheel:ISheel)
|
||||
public constructor(sheel:ISheel<Shell>)
|
||||
{
|
||||
sheel.onerror = (event) => {
|
||||
sheel.onerror = (event:any) => {
|
||||
this.result.catch = [event.target, event];
|
||||
this.events.catch.forEach(e => {
|
||||
e.call(event.target, event.target?.result);
|
||||
|
@ -419,7 +419,7 @@ class IEventLocate<Type>
|
|||
e.call(event.target, event.target?.result);
|
||||
})
|
||||
}
|
||||
sheel.onsuccess = (event) => {
|
||||
sheel.onsuccess = (event:any) => {
|
||||
this.result.then = [event.target, event];
|
||||
this.events.then.forEach(e => {
|
||||
e.call(event.target, event.target?.result);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<header></header>
|
||||
<main></main>
|
||||
<footer></footer>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<video controls style="width:50%;aspect-ratio: 2/1;">
|
||||
<track src="video.tr.vtt" kind="subtitles" srclang="tr" label="Türkçe" default>
|
||||
<track src="video.en.vtt" kind="subtitles" srclang="en" label="Engilişçe">
|
||||
<source src="video.webm" type="video/webm">
|
||||
</video>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,18 @@
|
|||
WEBVTT
|
||||
Kind: captions
|
||||
Language: tr
|
||||
|
||||
00:00:00.000 --> 00:00:04.240 position:100% align:center size:35%
|
||||
Abdussamed ULUTAŞ sunar
|
||||
|
||||
00:00:04.000 --> 00:00:05.000 position:100% align:center size:35%
|
||||
Alt yazı 1
|
||||
|
||||
00:00:05.000 --> 00:00:06.000 position:100% align:center size:35%
|
||||
Alt yazı 2
|
||||
|
||||
00:00:06.000 --> 00:00:07.000 position:100% align:center size:35%
|
||||
Alt yazı 3
|
||||
|
||||
00:00:07.000 --> 00:00:08.000 position:100% align:center size:35%
|
||||
Alt yazı 4
|
Binary file not shown.
Loading…
Reference in New Issue