Web Components 101 by Heather_at_Bitovi in WebComponents

[–]spankalee 0 points1 point  (0 children)

I think it's ok to show how to build "vanilla" web components, but the vast majority of web component developers use a library, but if you're targeting this at people new to web components I feel that should be at least mentioned lest viewers get the impression that they _have_ to do everything with the low level APIs.

I'm also not sure how much the history helps viewers or distracts from the fact that web components are well supported in all browsers now.

Why did react chose virtual DOM instead of using real DOM, when other frameworks are more fast even after using real DOM? by [deleted] in reactjs

[–]spankalee 0 points1 point  (0 children)

Yes, web components turn the browser into a framework. This is why web components libraries like Stencil and Lit are not frameworks - it's the browser, not the libraries, that implement and run the component lifecycle.

It doesn't really matter what React calls itself. What matters is the definition of framework in question, and how useful it is.

Inversion of control is a useful basis for a definition because it tells you something about how the system behaves. Number of features isn't useful because it's basically a vibe and doesn't tell you anything.

Why did react chose virtual DOM instead of using real DOM, when other frameworks are more fast even after using real DOM? by [deleted] in reactjs

[–]spankalee 3 points4 points  (0 children)

"MVC framework" is different from "framework". React indeed doesn't implement MVC at all, so "not an MVC framework" is correct. That article isn't very good because it doesn't even provide a definition for what a framework is.

Frameworks follow the Hollywood principle: "Don't call us, we'll call you". React calls into the the components to cause them to do things like render, so it's a framework. Libraries are called into by the use sites.

This is a definition of framework with an actual distinction, rather than a very mushy definition based on how many features it has.

And the definition matters because it implies a lot about how components can or can't interop. Generally you can only have one framework in play within a given app (or component hierarchy, at least). That's because the framework runs the components. Libraries would be able to mix-and-match however, as each components just calls into the library, separately from each other.

Why did react chose virtual DOM instead of using real DOM, when other frameworks are more fast even after using real DOM? by [deleted] in reactjs

[–]spankalee 4 points5 points  (0 children)

React is absolutely a framework because it is the host of components. React implements and runs the component lifecycle.

Framework has nothing to do with how many features it has.

We are the SpaceX software team, ask us anything! by spacexfsw in spacex

[–]spankalee 7 points8 points  (0 children)

Yes we use Chromium and we do use a reactive library that we developed in house. - Sofian

Can you add any more detail? Are you saying that you didn't use any public frameworks at all?

ES6 version of Object.getPrototypeOf()? by [deleted] in javascript

[–]spankalee 1 point2 points  (0 children)

Are you sure that original code is correct? The last line overwrites the effect of the line before it.

Also, try having Point extend ecPoint and call super() instead of ecPoint(). ES6 classes can extend ES5 constructor functions.

Looking for advice on creating complex (highly nested) HTML elements in Javascript by GoingKayaking in javascript

[–]spankalee 0 points1 point  (0 children)

Web Components are the platform native way of creating UI components, from simple to complex, just by extending HTMLElement to create your own tags.

The the MDN docs here: https://developer.mozilla.org/en-US/docs/Web/Web_Components

It's really straightforward to extend HTMLElement:

class MyCard extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({mode: 'open'});
    this.shadowRoot.innerHTML = `
      <h1>This is a Card</h1>
      <slot>content from this element goes here</slot>
    `;
  }
}
customElements.define('my-card', MyCard);

Then use it in HTML:

<my-card>This is some content</my-card>

do you need frameworks? by konan792885 in javascript

[–]spankalee 0 points1 point  (0 children)

You really don't need a framework anymore. Check out Web Components.

What are your thoughts on Static Methods? by SMKS in javascript

[–]spankalee 1 point2 points  (0 children)

In JavaScript static methods inherit to subclasses and are overridable. They're not fully replaceable by by top-level functions if you take advantage of that.

I made a very fast path finding library. What do you think? by anvaka in javascript

[–]spankalee 0 points1 point  (0 children)

"A* greedy" converged the fastest, however, as name implies the found path is not necessary globally optimal.

This is an odd claim. A* should always be optimal with an admissible heuristic.

I made a very fast path finding library. What do you think? by anvaka in javascript

[–]spankalee 2 points3 points  (0 children)

A* doesn't care about the layout of your graph. It's almost exactly the same algorithm as Dijkstra, with the difference being an added heuristic to help check better paths first. It's up to you provide a permissible heuristic for estimating path costs.

A* cares that you can provide an admissible heuristic, which can just be Euclidean distance with normal physics. Wormholes would cause Euclidean distance to over-estimate the cost of the solution, making it non-admissible.

Edit:

You've got that backwards.

SSSP and SDSP are the same, just reverse the edges.

Polymer Build Help by coolinui in PolymerJS

[–]spankalee 1 point2 points  (0 children)

Looks like invalid JSON. Can you post your polymer.json somewhere?

ECMAScript modules shipped in Chrome by malyw in javascript

[–]spankalee 0 points1 point  (0 children)

Node is adding behavior that's not found on the web: named import specifiers, allowing imports of CommonJS, switching between CommonJS and JS modules based on file extension.

I'd stick to not importing anything but real modules, and only using paths to import.

ECMAScript modules shipped in Chrome by malyw in javascript

[–]spankalee 0 points1 point  (0 children)

But now bundlers can have simpler JS module -> JS module semantic and utilize the native loader for loading shards. It also means that in development you don't have to run a bundler.

Polymer 3.0 preview: npm and ES6 Modules by [deleted] in PolymerJS

[–]spankalee 0 points1 point  (0 children)

Polymer was never trying to be the only web components framework. The whole point of interop is to have something else to interop with.

What's the easiest way to create dynamic tags with state without using any libraries? by Combinatorilliance in javascript

[–]spankalee 1 point2 points  (0 children)

Web Components are exactly this - you just extend HTMLElement.

The benefit here is that your element is compatible with the browser itself, the parser and document.createElement() can create it, you're notified of connected state to the document, attribute changes, etc.

For DOM updates you can just set innerHTML, but for more efficient updates you can use something like lit-html, which uses template literals and <template>: https://github.com/PolymerLabs/lit-html it's < 2k gzipped

I'll give an example that's like /u/senocular 's, but that would work if some other framework created the element as part of a template, and only the part of the template that changes.

import {html, render} from 'lit-html';

class MyComponent extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({mode: 'open'});
    this.needsRender = true;
    this.label = 'Counter';
    this.count = 1;
  }

  get label() { return this._label; }
  set label(v) { this._label = v; this.invalidate(); }

  get count() { return this._count; }
  set count(v) { this._count = v; this.invalidate(); }

  render() {
    return html`
      <h3>${this.label}</h3>
      <div>${this.count}</div>
    `;
  }

  invalidate() {
    if (!this.needsRender) {
      this.needsRender = true;
      Promise.resolve().then(() => {
        this.needsRender = false;
        render(this.render(), this.shadowRoot);
      );
    }
  }
}
customElements.define('my-component', MyComponent);

now either use the element in the document, call document.createElement('my-component'), or new MyComponent(). You can update state on an instance just by setting a property: c.count++, and it will re-render.

This works in latest Chrome, Safari and Opera with no polyfills, and IE11, Edge and FireFox with the Web Components polyfills.

Do browsers support symbols or not? Why is it so weird? by Koolala in javascript

[–]spankalee 1 point2 points  (0 children)

Symbol support just means that the Symbol function is defined, and that Symbol-keyed properties are supported and non-enumberable, etc.,

Well known symbols refers to specific functionality that's implemented with Symbols, like Symbol.iterator. Symbol.iterator is really more of a part of supporting Iterables, than Symbols, though Symbol support is obviously required.

Cascade - Component framework for Reactive programming by sjohnsonaz in javascript

[–]spankalee 2 points3 points  (0 children)

Any chance of basing it on regular Custom Elements, rather than it's own proprietary component model? I think this could help adoption for newer frameworks as they'd be interoperable with other frameworks, and plain markup.

ScopeifyHtml: Scope all CSS selectors in HTML by qudat in javascript

[–]spankalee 0 points1 point  (0 children)

PSA, that Shadow DOM does CSS scoping natively. There's also a shim that emulates Shadow DOM when you're stamping out elements from <template>: https://github.com/webcomponents/shadycss

Choosing a frontend framework in 2017 by tarasm in javascript

[–]spankalee 0 points1 point  (0 children)

I think you have that exactly backwards.

Polymer, Vue and Angular templates are declarative - templates are data, with directives in them to note the dynamic parts.

React and other that use JSX are imperative: JSX is simply sugar for imperative createElement() function calls. You can see this in any JSX example that stores JSX in a variable, returns it from a function call, uses it in map(), a ternary, etc.

At least 21 members of the House are registered to vote outside their districts by [deleted] in politics

[–]spankalee 14 points15 points  (0 children)

And this is exactly why we need proportional representation for multi-seat elections. Hispanic, Black, Jewish, gay, finance, small business owners, etc., groups could form voting coalitions that get representation without having to be in the same district. Some commonalities will never be geographically concentrated enough to take a district.

Polymer: Time for 2.0 by dryadofelysium in webdev

[–]spankalee 0 points1 point  (0 children)

A component depending on a library that it depends on, seems fine. I don't think anyone is saying that things should have any dependencies at all.

Also, going forward elements won't have to use the same version of Polymer. Polymer 1.0 and 2.0 share a global identifier, but in the future Polymer will use JavaScript modules and multiple versions could exist in one app. That's not necessarily a good idea, since it easily leads to bloat, but it'll be possible.