Skip to content

Commit

Permalink
setup for transition to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
copleykj committed Sep 28, 2024
1 parent db400ee commit 97dd710
Show file tree
Hide file tree
Showing 15 changed files with 4,088 additions and 1,769 deletions.
22 changes: 0 additions & 22 deletions .eslintrc.js

This file was deleted.

43 changes: 43 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"env": {
"browser": true,
"es2022": true,
"node": true
},
"extends": [
"standard",
"plugin:@typescript-eslint/eslint-recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"semi": [
"error",
"always"
],
"comma-dangle": [
"error",
"always-multiline"
],
"camelcase": 0,
"multiline-ternary": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-unused-vars": "off",
"no-useless-constructor": "off"
},
"ignorePatterns": [
"node_modules",
"tests"
],
"settings": {}
}
9 changes: 0 additions & 9 deletions .prettierrc.js

This file was deleted.

30 changes: 15 additions & 15 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Meteor } from 'meteor/meteor'
import { InjectData } from './namespace'
import { Meteor } from 'meteor/meteor';
import { InjectData } from './namespace';

// Automatically parse the inject-data payload on Meteor startup
// Load it into memory so it can be fetched by InjectData.getData
Meteor.startup(function() {
var dom = document.querySelectorAll(
'script[type="text/inject-data"]',
document
)
var injectedDataString = dom && dom.length > 0 ? dom[0].innerHTML : ''
InjectData._data = InjectData._decode(injectedDataString) || {}
})
Meteor.startup(function () {
const dom = document.querySelectorAll(
'script[type="text/inject-data"]',
document,
);
const injectedDataString = dom && dom.length > 0 ? dom[0].innerHTML : '';
InjectData._data = InjectData._decode(injectedDataString) || {};
});

/**
* Returns the data payload for the specified key.
* @param {string} key
* @param {function} callback
*/
InjectData.getData = function(key, callback) {
Meteor.startup(function() {
callback(InjectData._data[key])
})
}
InjectData.getData = function (key, callback) {
Meteor.startup(function () {
callback(InjectData._data[key]);
});
};
10 changes: 5 additions & 5 deletions lib/namespace.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global Package */
export const InjectData = {}
export const InjectData = {};

// Replace communitypackages:inject-data with our new API, this is for compatibility
// with third party packages that still depend upon the communitypackages version.
if (Package['communitypackages:inject-data']) {
Package['communitypackages:inject-data'].InjectData = InjectData
// Replace meteorhacks:inject-data with our new API, this is for compatibility
// with third party packages that still depend upon the meteorhacks version.
if (Package['meteorhacks:inject-data']) {
Package['meteorhacks:inject-data'].InjectData = InjectData;
}
92 changes: 46 additions & 46 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@

import { InjectData } from './namespace'
import { Meteor } from 'meteor/meteor'
import { WebAppInternals } from 'meteor/webapp'
import { InjectData } from './namespace';
import { Meteor } from 'meteor/meteor';
import { WebAppInternals } from 'meteor/webapp';

// Supports legacy uses of inject data, SSR users should turn this to false
InjectData.injectToHead = true
InjectData.injectToHead = true;
Meteor.startup(() => {
WebAppInternals.registerBoilerplateDataCallback(
'communitypackages:fast-render',
(req, data, arch) => {
if (
req &&
req.headers &&
req.headers._injectPayload &&
!InjectData.disableInjection
) {
const payload = `<script type="text/inject-data">${InjectData.encode(
req.headers._injectPayload
)}</script>`
WebAppInternals.registerBoilerplateDataCallback(
'communitypackages:fast-render',
(req, data) => {
if (
req &&
req.headers &&
req.headers._injectPayload &&
!InjectData.disableInjection
) {
const payload = `<script type="text/inject-data">${InjectData.encode(
req.headers._injectPayload,
)}</script>`;

if (InjectData.injectToHead) {
if (!data.dynamicHead) {
data.dynamicHead = ''
}
data.dynamicHead += payload
} else {
if (!data.dynamicBody) {
data.dynamicBody = ''
}
data.dynamicBody += payload
}
}
return false
}
)
})
if (InjectData.injectToHead) {
if (!data.dynamicHead) {
data.dynamicHead = '';
}
data.dynamicHead += payload;
} else {
if (!data.dynamicBody) {
data.dynamicBody = '';
}
data.dynamicBody += payload;
}
}
return false;
},
);
});

/**
* Pushes data into the InjectData payload.
Expand All @@ -43,24 +43,24 @@ Meteor.startup(() => {
* @param {*} value
*/
InjectData.pushData = function pushData (req, key, value) {
if (!req.headers) {
req.headers = {}
}
if (!req.headers._injectPayload) {
req.headers._injectPayload = {}
}
if (!req.headers) {
req.headers = {};
}
if (!req.headers._injectPayload) {
req.headers._injectPayload = {};
}

req.headers._injectPayload[key] = value
}
req.headers._injectPayload[key] = value;
};

/**
* Returns the object associated with the specified key.
* @param {string} key
*/
InjectData.getData = function getData (req, key) {
if (req.headers && req.headers._injectPayload) {
return Object.assign({}, req.headers._injectPayload[key])
} else {
return null
}
}
if (req.headers && req.headers._injectPayload) {
return Object.assign({}, req.headers._injectPayload[key]);
} else {
return null;
}
};
22 changes: 11 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { EJSON } from 'meteor/ejson'
import { InjectData } from './namespace'
import { EJSON } from 'meteor/ejson';
import { InjectData } from './namespace';

/**
* Returns an encoded string that represents an object.
* @param {object} ejson
*/
InjectData.encode = InjectData._encode = function(ejson) {
var ejsonString = EJSON.stringify(ejson)
return encodeURIComponent(ejsonString)
}
InjectData.encode = InjectData._encode = function (ejson) {
const ejsonString = EJSON.stringify(ejson);
return encodeURIComponent(ejsonString);
};

/**
* Decodes an encoded string into an object.
* @param {string} encodedEjson
*/
InjectData.decode = InjectData._decode = function(encodedEjson) {
var decodedEjsonString = decodeURIComponent(encodedEjson)
if (!decodedEjsonString) return null
InjectData.decode = InjectData._decode = function (encodedEjson) {
const decodedEjsonString = decodeURIComponent(encodedEjson);
if (!decodedEjsonString) return null;

return EJSON.parse(decodedEjsonString)
}
return EJSON.parse(decodedEjsonString);
};
Loading

0 comments on commit 97dd710

Please sign in to comment.