Skip to content

Commit eb2cc7a

Browse files
committed
add provide store syntax helper
1 parent 48c76b2 commit eb2cc7a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

examples/counter-start/src/components/Counter.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ function Counter() {
100100

101101
export default function CounterRoot() {
102102
'use stateprovider';
103-
const globalCount = provideState(GlobalCount);
103+
const globalCount = GlobalCount;
104104
return <Counter />;
105105
}

packages/state/src/api-definition.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
22
ApiDefinitionCreator,
33
ApiDefinitionInternalCreator,
4+
ExtractStore,
45
GenericStoreApi,
56
Plugin,
67
PluginContext,
78
} from '~/types';
89
import { $CREATOR, $PLUGIN } from '~/api';
10+
import { provideState } from './solid';
911

1012
/**
1113
* @internal
@@ -43,4 +45,11 @@ export class ApiDefinition<T extends GenericStoreApi, E extends {}>
4345
TExtendedSignal & Omit<E, keyof TExtendedSignal>
4446
>;
4547
}
48+
49+
/**
50+
* Shorthand helper syntax for `provideState(MyStore)`
51+
*/
52+
provide(): ExtractStore<this> {
53+
return provideState(this);
54+
}
4655
}

packages/state/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface ApiDefinitionCreator<
2424
TStoreApi,
2525
TExtendedSignal & Omit<TSignalExtension, keyof TExtendedSignal>
2626
>;
27+
28+
provide(): ExtractStore<this>;
2729
}
2830

2931
export interface ApiDefinitionInternalCreator<

0 commit comments

Comments
 (0)