Skip to content

Instantly share code, notes, and snippets.

View pmdartus's full-sized avatar
🤣

Pierre-Marie Dartus pmdartus

🤣
View GitHub Profile
@pmdartus
pmdartus / consumer-symbol.js
Created October 4, 2022 08:09
Example context consumer
import { LightningElement } from 'lwc';
import { I18nContextSymbol } from 'i18n/context';
// https://vuejs.org/guide/components/provide-inject.html#working-with-symbol-keys
export default class Foo extends LightningElement {
static context = {
[I18nContextSymbol]: { from: '18n' }
};
connectedCallback() {

Async map

Implement a function asyncMap.

This function produces an array of values by mapping each value in arr through the iteratee function in parallel. The iteratee function accepts a first argument an item from arr and a Node.js style callback (accepting an error as first argument or null and the mapped item as second argument). If the iteratee produces a error the main callback is invoked with the error as first argument, otherwise the main callback is invoked with null as first argument and the array of mapped items as second argument.

function asyncMap(arr, fn, cb) {
    // TODO
@pmdartus
pmdartus / dry-run
Created February 2, 2021 08:36
Test rebaseline
vpython .\third_party\blink\tools\blink_tool.py rebaseline-cl --no-trigger-jobs --dry-run --fill-missing
2021-02-02 09:16:35,000 - Finished try jobs:
2021-02-02 09:16:35,000 - fuchsia_x64
2021-02-02 09:16:35,000 - linux-rel
2021-02-02 09:16:35,000 - mac-rel
2021-02-02 09:16:35,000 - win10_chromium_x64_rel_ng
2021-02-02 09:16:36,701 - There are some builders with no results:
2021-02-02 09:16:36,701 - linux-blink-rel
2021-02-02 09:16:36,701 - linux-wpt-identity-fyi-rel
2021-02-02 09:16:36,703 - linux-wpt-input-fyi-rel
@pmdartus
pmdartus / amd-loader.html
Created August 19, 2020 15:13
AMD Loader example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js" integrity="sha512-vRqhAr2wsn+/cSsyz80psBbCcqzz2GTuhGk3bq3dAyytz4J/8XwFqMjiAGFBj+WM95lHBJ9cDf87T3P8yMrY7A==" crossorigin="anonymous"></script>
@pmdartus
pmdartus / lwc-no-vdom.js
Created July 23, 2020 15:38
Test LWC compiler output without VDOM
'use strict';
/* proxy-compat-disable */
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
@pmdartus
pmdartus / test.html
Created June 15, 2020 14:12
CSS injection vs. clone performance
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="container"></div>
@pmdartus
pmdartus / polyfill.js
Created March 20, 2020 08:41
String.prototype.endsWith polyfill
if (!String.prototype.endsWith) {
Object.defineProperty(String.prototype, 'endsWith', {
value: function (searchString, position) {
var subjectString = this.toString();
if (position === undefined || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
@pmdartus
pmdartus / original.css
Created February 14, 2020 15:11
Max call stack error LWC compiler
.unit-content .codeblock {
word-wrap: break-word;
}
.unit-content blockquote {
border-color: #e2e2e2;
}
.unit-content blockquote p {
font-weight: normal;
@pmdartus
pmdartus / lwc.rollup.config.js
Last active February 12, 2020 17:28
Rollup configuration for size comparison
// Run via `yarn rollup -c rollup.config.js` at the root of the lwc repo
import path from 'path';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
const input = path.resolve(__dirname, 'packages/lwc/dist/engine/esm/es2017/engine.js');
const replaceConfig = {
'process.env.NODE_ENV': JSON.stringify('production'),
};
@pmdartus
pmdartus / performance.md
Created October 18, 2019 05:46
Constructor & prototype reform
Test name Before (ops/sec) After (ops/sec) Delta
dom/compare-document-position/compare ancestor 19,973 19,995 0.11%
dom/compare-document-position/compare descendant 21,624 20,156 -6.79%
dom/compare-document-position/compare siblings 1,138,911 1,128,045 -0.95%
dom/construction/createComment 1,446,494 1,337,418 -7.54%
dom/construction/createDocumentFragment 1,515,799 1,376,833 -9.17%
dom/construction/createElement 223,089 185,578 -16.81%
dom/construction/createEvent 208,710 199,711 -4.31%
dom/construction/create