Skip to content

Commit

Permalink
Merge pull request #177 from Financial-Times/deprecate-javascript
Browse files Browse the repository at this point in the history
Deprecate javascript utils
  • Loading branch information
apaleslimghost authored Sep 12, 2024
2 parents 032a365 + 2247264 commit 3bb178d
Show file tree
Hide file tree
Showing 14 changed files with 7,946 additions and 20,923 deletions.
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# generator: n-circle2-cli
# template: component

references:

container_config_node: &container_config_node
working_directory: ~/project/build
docker:
Expand Down
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['@financial-times/eslint-config-next'],
rules: {
// allow console for the deprecation warnings
'no-console': 'off'
}
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
.eslintrc.js
.editorconfig
.stylelintrc
test/styles.css
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,4 @@ node_modules/@financial-times/n-gage/index.mk:

export IGNORE_A11Y = true;

test-unit:
@karma start karma.conf.js
@$(DONE)

test-unit-dev:
@karma start karma.conf.js --single-run false --auto-watch true

test: verify test-unit

test-dev: verify test-unit-dev
test: verify
41 changes: 0 additions & 41 deletions js/cookies.js

This file was deleted.

6 changes: 0 additions & 6 deletions js/perf-mark.js

This file was deleted.

68 changes: 0 additions & 68 deletions js/to-ascii.js

This file was deleted.

150 changes: 0 additions & 150 deletions karma.conf.js

This file was deleted.

47 changes: 13 additions & 34 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
const { debounce, throttle } = require('@financial-times/o-utils/main');
const cookieStore = require('./js/cookies');
const getSpoorNumber = () => {
let spoorId = cookieStore.get('spoor-id').replace(/-/g, '');
spoorId = spoorId.substring(spoorId.length - 12, spoorId.length); // Don't overflow the int
return parseInt(spoorId, 16);
};

module.exports = {
$: function (sel, ctx) { return (ctx || document).querySelector(sel); },
$$: function (sel, ctx) { return [].slice.call((ctx || document).querySelectorAll(sel));},
debounce,
throttle,
uuid: function uuid (a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,uuid);},
ascii: require('./js/to-ascii'),
broadcast: function (name, data, bubbles = true) {
const rootEl = Element.prototype.isPrototypeOf(this) ? this : document.body;
$ (sel, ctx) {
console.error(`n-ui-foundations $ is deprecated. please use ${ctx ? 'el' : 'document'}.querySelector('${sel}') directly`);
return (ctx || document).querySelector(sel);
},
$$ (sel, ctx) {
console.error(`n-ui-foundations $$ is deprecated. please use ${ctx ? 'el' : 'document'}.querySelectorAll('${sel}') directly`);
return [].slice.call((ctx || document).querySelectorAll(sel));
},
broadcast (name, data, bubbles = true) {
const isElement = Element.prototype.isPrototypeOf(this);
const rootEl = isElement ? this : document.body;

console.error(`n-ui-foundations broadcast is deprecated. please use ${isElement ? 'el' : 'document.body'}.dispatchEvent(new CustomEvent('${name}', { bubbles: true, cancelable: true, detail: EVENT_DATA })) directly`);
let event;

try {
Expand All @@ -24,22 +21,4 @@ module.exports = {
}
rootEl.dispatchEvent(event);
},
perfMark: require('./js/perf-mark'),
sampleUsers: (pct, seed) => {
if (!seed) {
throw new Error('sampleUsers needs a seed string to be passed in as the second parameter');
}
const seedAsNumber = seed.split('').reduce((num, str, i) => num + Math.pow(2, i) * str.charCodeAt(0), 0);
return (getSpoorNumber() + seedAsNumber) % 100 < pct;
},
cookieStore,
createToggler: ({ flag = true, callback }) => {
return () => {
if (typeof callback === 'function') {
callback({ flag });
}
flag = !flag;
return flag;
};
}
};
Loading

0 comments on commit 3bb178d

Please sign in to comment.