-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: proof of context for analytics context
- Loading branch information
1 parent
dcf1ef0
commit 34f6945
Showing
11 changed files
with
353 additions
and
67 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,27 @@ | ||
<script setup lang="ts"> | ||
import { useEventContext } from '@dpc-sdp/ripple-ui-core' | ||
interface ITestContextProps { | ||
context: any | ||
} | ||
const props = withDefaults(defineProps<ITestContextProps>(), {}) | ||
const { context } = useEventContext(props.context) | ||
</script> | ||
|
||
<template> | ||
<div class="testing123"> | ||
{{ context }} | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.testing123 { | ||
padding: 20px; | ||
margin: 10px 0; | ||
border: 1px solid; | ||
background-color: rgba(0,0,0,0.05); | ||
} | ||
</style> |
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,27 @@ | ||
<script setup lang="ts"> | ||
import { useEventContext } from '@dpc-sdp/ripple-ui-core' | ||
interface ITestContextProps { | ||
objKey: any | ||
on: any | ||
off: any | ||
} | ||
const props = withDefaults(defineProps<ITestContextProps>(), {}) | ||
const { context, updateContext } = useEventContext() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
Change <b>{{ objKey }}</b> | ||
<button class="rpl-button" @click="updateContext(objKey, on)"> | ||
{{ on }} | ||
</button> | ||
<button class="rpl-button" @click="updateContext(objKey, off)"> | ||
{{ off }} | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<style scoped></style> |
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,26 @@ | ||
<script setup lang="ts"> | ||
import { useEventContext } from '@dpc-sdp/ripple-ui-core' | ||
interface ITestContextProps { | ||
} | ||
const props = withDefaults(defineProps<ITestContextProps>(), {}) | ||
const { context } = useEventContext() | ||
</script> | ||
|
||
<template> | ||
<div class="testing123"> | ||
{{ context }} | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.testing123 { | ||
padding: 20px; | ||
margin: 10px 0; | ||
border: 1px solid; | ||
background-color: rgba(0,0,0,0.05); | ||
font-size: 16px; | ||
} | ||
</style> |
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,34 @@ | ||
<script setup lang="ts"> | ||
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core' | ||
interface ITestContextProps { | ||
name: any | ||
} | ||
const emit = defineEmits<{}>() | ||
const props = withDefaults(defineProps<ITestContextProps>(), {}) | ||
const { emitRplEvent } = useRippleEvent('testing', emit) | ||
const fire = () => { | ||
emitRplEvent( | ||
'testFire', | ||
{ | ||
action: 'search' | ||
}, | ||
{ global: true } | ||
) | ||
nextTick() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<button class="rpl-button" @click="fire"> | ||
Fire "testing/testFire" event | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<style scoped></style> |
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
48 changes: 48 additions & 0 deletions
48
packages/ripple-ui-core/src/composables/useEventContext.ts
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,48 @@ | ||
import { computed, provide, inject, ref } from 'vue' | ||
|
||
export default (addedContext?) => { | ||
const { context: parentContext, updateContext: updateParentContext } = | ||
inject<any>('rplEventContext', {}) | ||
|
||
if (!addedContext) { | ||
return { | ||
context: parentContext, | ||
updateContext: updateParentContext | ||
} | ||
} | ||
|
||
const context = ref(addedContext || {}) | ||
|
||
function updateContext(key, value) { | ||
|
||
|
||
if (typeof updateParentContext === 'function') { | ||
updateParentContext(key, value) | ||
} | ||
if (context.value?.hasOwnProperty(key)) { | ||
context.value = { | ||
...context.value, | ||
[key]: value | ||
} | ||
} | ||
|
||
} | ||
|
||
const mergedContext = computed(() => { | ||
|
||
return { | ||
...(parentContext?.value || {}), | ||
...(context.value || {}) | ||
} | ||
}) | ||
|
||
provide('rplEventContext', { | ||
context: mergedContext, | ||
updateContext | ||
}) | ||
|
||
return { | ||
context: mergedContext, | ||
updateContext | ||
} | ||
} |
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