@@ -875,11 +875,7 @@ export function is_signal(val) {
875
875
* @returns {T }
876
876
*/
877
877
export function getContext ( key ) {
878
- if ( current_component_context === null ) {
879
- e . lifecycle_outside_component ( 'getContext' ) ;
880
- }
881
-
882
- const context_map = get_or_init_context_map ( current_component_context ) ;
878
+ const context_map = get_or_init_context_map ( 'getContext' ) ;
883
879
const result = /** @type {T } */ ( context_map . get ( key ) ) ;
884
880
885
881
if ( DEV ) {
@@ -907,11 +903,7 @@ export function getContext(key) {
907
903
* @returns {T }
908
904
*/
909
905
export function setContext ( key , context ) {
910
- if ( current_component_context === null ) {
911
- e . lifecycle_outside_component ( 'setContext' ) ;
912
- }
913
-
914
- const context_map = get_or_init_context_map ( current_component_context ) ;
906
+ const context_map = get_or_init_context_map ( 'setContext' ) ;
915
907
context_map . set ( key , context ) ;
916
908
return context ;
917
909
}
@@ -925,11 +917,7 @@ export function setContext(key, context) {
925
917
* @returns {boolean }
926
918
*/
927
919
export function hasContext ( key ) {
928
- if ( current_component_context === null ) {
929
- e . lifecycle_outside_component ( 'hasContext' ) ;
930
- }
931
-
932
- const context_map = get_or_init_context_map ( current_component_context ) ;
920
+ const context_map = get_or_init_context_map ( 'hasContext' ) ;
933
921
return context_map . has ( key ) ;
934
922
}
935
923
@@ -943,11 +931,7 @@ export function hasContext(key) {
943
931
* @returns {T }
944
932
*/
945
933
export function getAllContexts ( ) {
946
- if ( current_component_context === null ) {
947
- e . lifecycle_outside_component ( 'getAllContexts' ) ;
948
- }
949
-
950
- const context_map = get_or_init_context_map ( current_component_context ) ;
934
+ const context_map = get_or_init_context_map ( 'getAllContexts' ) ;
951
935
952
936
if ( DEV ) {
953
937
// @ts -expect-error
@@ -963,11 +947,17 @@ export function getAllContexts() {
963
947
}
964
948
965
949
/**
966
- * @param {import('#client').ComponentContext } context
950
+ * @param {string } name
967
951
* @returns {Map<unknown, unknown> }
968
952
*/
969
- function get_or_init_context_map ( context ) {
970
- return ( context . c ??= new Map ( get_parent_context ( context ) || undefined ) ) ;
953
+ function get_or_init_context_map ( name ) {
954
+ if ( current_component_context === null ) {
955
+ e . lifecycle_outside_component ( name ) ;
956
+ }
957
+
958
+ return ( current_component_context . c ??= new Map (
959
+ get_parent_context ( current_component_context ) || undefined
960
+ ) ) ;
971
961
}
972
962
973
963
/**
0 commit comments