Skip to content

Commit 47a7a71

Browse files
authored
feat: update to latest component-relay (#61)
* feat: update to latest component-relay * fix: refactor main.js * chore: build Co-authored-by: Johnny Almonte <[email protected]>
1 parent f7c6bdc commit 47a7a71

File tree

7 files changed

+36
-44
lines changed

7 files changed

+36
-44
lines changed

app/App.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/components/Home.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ComponentManager from 'sn-components-api';
2+
import ComponentRelay from '@standardnotes/component-relay';
33

44
export default class Home extends React.Component {
55

@@ -104,14 +104,14 @@ export default class Home extends React.Component {
104104
// Be sure to capture this object as a variable, as this.note may be reassigned in `streamContextItem`, so by the time
105105
// you modify it in the presave block, it may not be the same object anymore, so the presave values will not be applied to
106106
// the right object, and it will save incorrectly.
107-
let note = this.note;
107+
const note = this.note;
108108

109-
this.componentManager.saveItemWithPresave(note, () => {
109+
this.componentRelay.saveItemWithPresave(note, () => {
110110
note.content.preview_html = null;
111111
note.content.preview_plain = 'Created with Secure Spreadsheets';
112112

113-
let json = this.getJSON();
114-
let content = JSON.stringify(json);
113+
const json = this.getJSON();
114+
const content = JSON.stringify(json);
115115
note.content.text = content;
116116
});
117117
}
@@ -124,23 +124,17 @@ export default class Home extends React.Component {
124124
}
125125

126126
connectToBridge() {
127-
const permissions = [
128-
{
129-
name: 'stream-context-item'
130-
}
131-
];
132-
133-
this.componentManager = new ComponentManager(permissions, () => {
134-
// on ready
135-
const platform = this.componentManager.platform;
136-
if (platform) {
137-
document.body.classList.add(platform);
127+
this.componentRelay = new ComponentRelay({
128+
targetWindow: window,
129+
onReady: () => {
130+
const { platform } = this.componentRelay;
131+
if (platform) {
132+
document.body.classList.add(platform);
133+
}
138134
}
139135
});
140136

141-
// componentManager.loggingEnabled = true;
142-
143-
this.componentManager.streamContextItem((note) => {
137+
this.componentRelay.streamContextItem((note) => {
144138
this.note = note;
145139

146140
// Only update UI on non-metadata updates.

app/main.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import App from './App';
3+
import Home from './components/Home';
4+
5+
class App extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
}
9+
10+
render() {
11+
return (
12+
<div className="sn-component">
13+
<Home />
14+
</div>
15+
);
16+
}
17+
}
418

519
ReactDOM.render(
620
<App />,

dist/dist.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@babel/plugin-transform-runtime": "^7.10.1",
2121
"@babel/preset-env": "^7.14.7",
2222
"@babel/preset-react": "^7.10.1",
23+
"@standardnotes/component-relay": "2.2.0",
2324
"@standardnotes/eslint-config-extensions": "^1.0.4",
2425
"babel-loader": "^8.2.2",
2526
"copy-webpack-plugin": "^9.0.1",
@@ -31,7 +32,6 @@
3132
"react": "16.x",
3233
"react-dom": "16.x",
3334
"sass-loader": "^11.0.1",
34-
"sn-components-api": "1.2.8",
3535
"sn-stylekit": "2.0.22",
3636
"style-loader": "^3.0.0",
3737
"terser-webpack-plugin": "^5.1.4",

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
test: /\.js[x]?$/,
3030
include: [
3131
path.resolve(__dirname, 'app'),
32-
path.resolve(__dirname, 'node_modules/sn-components-api/dist/dist.js')
32+
path.resolve(__dirname, 'node_modules/@standardnotes/component-relay/dist/dist.js')
3333
],
3434
exclude: /node_modules/,
3535
use: ['babel-loader']

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,11 @@
989989
"@nodelib/fs.scandir" "2.1.5"
990990
fastq "^1.6.0"
991991

992+
"@standardnotes/[email protected]":
993+
version "2.2.0"
994+
resolved "https://registry.yarnpkg.com/@standardnotes/component-relay/-/component-relay-2.2.0.tgz#3b51e1047997e624594c8bce00c38e73d49cfb8f"
995+
integrity sha512-cJMSnT/fREYK1zq/U6aSfxWPiLPhzI1sLNDUMhmZnJ2npBKFeqE7qQj7NGdp4Q5f72yk4Oqevg5O2BxWDKpYHA==
996+
992997
"@standardnotes/eslint-config-extensions@^1.0.4":
993998
version "1.0.4"
994999
resolved "https://registry.yarnpkg.com/@standardnotes/eslint-config-extensions/-/eslint-config-extensions-1.0.4.tgz#451a90b3f140aa19430023d887fb143c4f6df2bd"
@@ -5248,11 +5253,6 @@ slice-ansi@^4.0.0:
52485253
astral-regex "^2.0.0"
52495254
is-fullwidth-code-point "^3.0.0"
52505255

5251-
5252-
version "1.2.8"
5253-
resolved "https://registry.yarnpkg.com/sn-components-api/-/sn-components-api-1.2.8.tgz#5fbba6652c08d5b3e92502d782453c1520165721"
5254-
integrity sha512-epBFsQIKLK78SnJ6e5JNjYbdOAYbKzRyydjpAqji0WdX3S/tOD5Z3UVdLVyi4orKaM4322dk6nRJiTHMI1VyIw==
5255-
52565256
52575257
version "2.0.22"
52585258
resolved "https://registry.yarnpkg.com/sn-stylekit/-/sn-stylekit-2.0.22.tgz#1ead6ed7ab6e2f4dd12759dc82b88d88d10d877e"

0 commit comments

Comments
 (0)