-
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.
allow to inject states from parent context
- Loading branch information
1 parent
ec29662
commit 5b80856
Showing
8 changed files
with
147 additions
and
67 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
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,36 @@ | ||
import { | ||
createRoot, | ||
getOwner, | ||
onCleanup, | ||
type Owner, | ||
runWithOwner, | ||
} from 'solid-js'; | ||
|
||
type Disposable<T> = (dispoe: () => void) => T; | ||
|
||
function createSubRoot<T>( | ||
fn: Disposable<T>, | ||
owner: typeof Owner = getOwner(), | ||
): T { | ||
return createRoot((dispose) => { | ||
owner && runWithOwner(owner, onCleanup.bind(void 0, dispose)); | ||
return fn(dispose); | ||
}, owner!); | ||
} | ||
|
||
export function runInSubRoot<T>(fn: Disposable<T>, owner?: typeof Owner): T { | ||
let error: unknown; | ||
const result = createSubRoot((dispose) => { | ||
try { | ||
return fn(dispose); | ||
} catch (e) { | ||
error = e; | ||
dispose(); | ||
throw e; | ||
} | ||
}, owner); | ||
if (error) { | ||
throw error; | ||
} | ||
return result; | ||
} |
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,8 +1,16 @@ | ||
export { provideState, StateProvider } from './provider'; | ||
export { provideState, StateProvider, getStateContext } from './provider'; | ||
|
||
export { defineStore, type Store, type StoreValue } from './store'; | ||
|
||
export { | ||
defineSignal, | ||
type Signal, | ||
type SignalDefinitionCreator, | ||
} from './signal'; | ||
|
||
export { | ||
ɵdefineResource, | ||
ɵWithResourceStorage, | ||
type ResourceActions, | ||
type Resource, | ||
} from './resource'; |
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