-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from aleph1/2.0.0-beta
2.0.0 release
- Loading branch information
Showing
19 changed files
with
1,293 additions
and
5,461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Simple Observable Proxy Demo</title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body> | ||
Check the console :) | ||
<script type="module"> | ||
import { observable, ObservableEvents, on } from '../dist/simple-observable-proxy.js'; | ||
// create | ||
const sharedState = observable([ | ||
{ | ||
id: 1, | ||
name: 'My first book.' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'My second book.' | ||
} | ||
]); | ||
|
||
const sharedStateCallback1 = state => { | ||
console.log('sharedStateCallback1()'); | ||
}; | ||
|
||
const sharedStateCallback2 = state => { | ||
console.log('sharedStateCallback2()'); | ||
}; | ||
|
||
on(sharedState, ObservableEvents.change, sharedStateCallback1); | ||
on(sharedState, ObservableEvents.change, sharedStateCallback2); | ||
|
||
sharedState.push({ | ||
id: 3, | ||
name: 'My third book.' | ||
}); | ||
|
||
// log: sharedStateCallback1(); | ||
// log: sharedStateCallback2(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
export type PlainObject = { | ||
export type Observable = { | ||
[name: string]: any; | ||
}; | ||
type ObservableCallback = () => void; | ||
export declare const observable: (data: any) => PlainObject | boolean; | ||
export declare const observe: (observableProxy: any, callback: ObservableCallback) => boolean; | ||
export declare const unobserve: (observableProxy: any | PlainObject, callback: ObservableCallback) => boolean; | ||
export declare const destroy: (observableProxy: any) => boolean; | ||
export type ObservableCallback = (proxy: Observable) => void; | ||
export declare const ObservableEvents: { | ||
readonly change: "change"; | ||
readonly destroy: "destroy"; | ||
}; | ||
type ObservableEventKey = keyof typeof ObservableEvents; | ||
export type ObservableEvent = typeof ObservableEvents[ObservableEventKey]; | ||
type ObservableCallbackObject = { | ||
change: Set<ObservableCallback>; | ||
destroy: Set<ObservableCallback>; | ||
}; | ||
export type ObservableCallbackMap = Map<Observable, ObservableCallbackObject>; | ||
export declare const observable: (data: Observable) => Observable; | ||
export declare const on: (observableProxy: Observable, eventType: ObservableEventKey, callback: ObservableCallback) => boolean; | ||
export declare const off: (observableProxy: Observable, eventType: ObservableEventKey, callback: ObservableCallback) => boolean; | ||
export declare const observe: (observableProxy: Observable, callback: ObservableCallback) => boolean; | ||
export declare const unobserve: (observableProxy: Observable, callback: ObservableCallback) => boolean; | ||
export declare const destroy: (observableProxy: Observable) => boolean; | ||
export {}; |
Oops, something went wrong.