Skip to content

Commit cbe577c

Browse files
patinthehatPatrick
authored andcommitted
fix SpruceProxy.displayTracking() breaking
1 parent 2a85640 commit cbe577c

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/SpruceProxy.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class SpruceProxy {
1313

1414
constructor(window: any = null, rayInstance: any = null) {
1515
this.window = window ?? getWindow();
16-
this.rayInstance = rayInstance ?? ray;
16+
this.rayInstance = rayInstance ?? ray();
1717
this.spruceInstance = this.window.Spruce;
1818
}
1919

@@ -73,7 +73,7 @@ export class SpruceProxy {
7373

7474
public displayTracking(key: string, action: string, value: any) {
7575
if (typeof trackRays[<string>key] === 'undefined') {
76-
trackRays[<string>key] = this.rayInstance();
76+
trackRays[<string>key] = this?.rayInstance() ?? ray();
7777
}
7878

7979
const data = {
@@ -88,10 +88,12 @@ export class SpruceProxy {
8888
}
8989

9090
public dumpStore(name: string) {
91-
this.rayInstance().table(this.spruceInstance.stores[name]);
91+
const rayInstance = this?.rayInstance ?? ray;
92+
rayInstance().table(this.spruceInstance.stores[name]);
9293
}
9394

9495
public dumpAllStores() {
95-
this.rayInstance().table(this.spruceInstance.stores);
96+
const rayInstance = this?.rayInstance ?? ray;
97+
rayInstance().table(this.spruceInstance.stores);
9698
}
9799
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { getWindow } from './lib/utils';
55

66
export { bootstrapImports } from './BootstrapImports';
77

8-
initializeLibrary([AlpineRayPlugin], getWindow(), ray());
8+
initializeLibrary([AlpineRayPlugin], getWindow(), ray);
99

1010
export default AlpineRayPlugin;

tests/SpruceProxy.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class FakeRay {
4646

4747
beforeEach(() => {
4848
win = {
49+
ray(...args: any[]) {
50+
if (!args.length) {
51+
return new FakeRay();
52+
}
53+
return new FakeRay().send('log', ...args);
54+
},
4955
axios: {},
5056
alpineRayConfig: {
5157
logComponentsInit: false,

0 commit comments

Comments
 (0)