Skip to content

Commit

Permalink
fix: 🐛 Fix assigning to widget object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Baše authored and mjancarik committed Aug 9, 2023
1 parent 2960ff2 commit 6a89efa
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 35 deletions.
8 changes: 2 additions & 6 deletions packages/plugin-component/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setDefaultValueForUndefined } from '@merkur/core';
import { assignMissingKeys, setDefaultValueForUndefined } from '@merkur/core';

export function componentPlugin() {
return {
Expand Down Expand Up @@ -29,11 +29,7 @@ export function componentPlugin() {
suspendedTasks: [],
};

widget = {
...widgetProperties,
...componentAPI(),
...widget,
};
assignMissingKeys(widget, componentAPI(), widgetProperties);

widget = setDefaultValueForUndefined(widget, ['props', 'state']);
widget = setDefaultValueForUndefined(widget, ['assets'], []);
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-event-emitter/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { assignMissingKeys } from '@merkur/core';

export function eventEmitterPlugin() {
return {
async setup(widget) {
widget = {
...eventEmitterAPI(),
...widget,
};
assignMissingKeys(widget, eventEmitterAPI());

widget.$in.eventEmitter = {
event: {},
Expand Down
7 changes: 2 additions & 5 deletions packages/plugin-graphql-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bindWidgetToFunctions } from '@merkur/core';
import { assignMissingKeys, bindWidgetToFunctions } from '@merkur/core';

import { print, visit, stripIgnoredCharacters } from 'graphql';

Expand Down Expand Up @@ -30,10 +30,7 @@ function setEntityClasses(widget, entityClasses) {
function graphqlClientPlugin() {
return {
async setup(widget) {
widget = {
...graphqlClientAPI(),
...widget,
};
assignMissingKeys(widget, graphqlClientAPI());

widget.$in.graphqlClient = {
endpointUrl: '',
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-http-cache/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { bindWidgetToFunctions, hookMethod } from '@merkur/core';
import {
assignMissingKeys,
bindWidgetToFunctions,
hookMethod,
} from '@merkur/core';
import { setDefaultConfig, copyResponse } from '@merkur/plugin-http-client';

import CacheEntry from './CacheEntry';
Expand Down Expand Up @@ -32,10 +36,7 @@ export function httpCachePlugin() {
);
}

widget = {
...httpCacheAPI(),
...widget,
};
assignMissingKeys(widget, httpCacheAPI());

widget.$in.httpClient.cache = new Map();

Expand Down
7 changes: 2 additions & 5 deletions packages/plugin-http-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bindWidgetToFunctions } from '@merkur/core';
import { assignMissingKeys, bindWidgetToFunctions } from '@merkur/core';

export function setDefaultConfig(widget, newDefaultConfig) {
widget.$in.httpClient.defaultConfig = {
Expand All @@ -17,10 +17,7 @@ export function getDefaultTransformers(widget) {
export function httpClientPlugin() {
return {
async setup(widget) {
widget = {
...httpClientAPI(),
...widget,
};
assignMissingKeys(widget, httpClientAPI());

widget.$in.httpClient = {
defaultConfig: {
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-router/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
assignMissingKeys,
bindWidgetToFunctions,
setDefaultValueForUndefined,
hookMethod,
Expand Down Expand Up @@ -27,10 +28,7 @@ export function createRouter(widget, routes, options) {
export function routerPlugin() {
return {
async setup(widget) {
widget = {
...routerAPI(),
...widget,
};
assignMissingKeys(widget, routerAPI());

widget.$in.router = {
route: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-session-storage/src/__tests__/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('Session Storage plugin', () => {
widget.$dependencies.sessionStorage.setItem.mockImplementationOnce(() => {
throw new Error('setItem error');
});
jest.spyOn(console, 'error').mockImplementationOnce();
jest.spyOn(console, 'error').mockImplementation();

expect(console.error).not.toHaveBeenCalled();

Expand Down
7 changes: 2 additions & 5 deletions packages/plugin-session-storage/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bindWidgetToFunctions } from '@merkur/core';
import { assignMissingKeys, bindWidgetToFunctions } from '@merkur/core';

const KEY_PREFIX_SEPARATOR = '__';

Expand All @@ -18,10 +18,7 @@ export function setKeyPrefix(
export function sessionStoragePlugin() {
return {
async setup(widget) {
widget = {
...sessionStorageAPI(),
...widget,
};
assignMissingKeys(widget, sessionStorageAPI());

widget.$in.sessionStorage = {};
setKeyPrefix(widget);
Expand Down

0 comments on commit 6a89efa

Please sign in to comment.