Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fast-element): every third subscriber not registered #3086

Merged
merged 3 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(fast-element): every third subscriber not registered
  • Loading branch information
Rob Eisenberg committed May 8, 2020
commit 56ad47e995fa572268628b6e49edaa1faeb200b2
34 changes: 16 additions & 18 deletions packages/web-components/fast-element/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,12 @@ export class HTMLView implements ElementView, SyntheticView {
// @public (undocumented)
export const lastAttributeNameRegex: RegExp;

// @public (undocumented)
// @public
export interface Notifier {
// (undocumented)
notify(source: any, args: any): void;
// (undocumented)
subscribe(subscriber: Subscriber, context?: any): void;
// (undocumented)
unsubscribe(subscriber: Subscriber, context?: any): void;
notify(args: any): void;
readonly source: any;
subscribe(subscriber: Subscriber, propertyToWatch?: any): void;
unsubscribe(subscriber: Subscriber, propertyToUnwatch?: any): void;
}

// @public (undocumented)
Expand Down Expand Up @@ -458,14 +456,14 @@ export type PartialFASTElementDefinition = {
readonly elementOptions?: ElementDefinitionOptions;
};

// @public (undocumented)
// @public
export class PropertyChangeNotifier implements Notifier {
constructor(source: any);
notify(propertyName: string): void;
// (undocumented)
notify(source: any, propertyName: string): void;
// (undocumented)
subscribe(subscriber: Subscriber, propertyName: string): void;
// (undocumented)
unsubscribe(subscriber: Subscriber, propertyName: string): void;
readonly source: any;
subscribe(subscriber: Subscriber, propertyToWatch: string): void;
unsubscribe(subscriber: Subscriber, propertyToUnwatch: string): void;
}

// @public (undocumented)
Expand Down Expand Up @@ -567,17 +565,17 @@ export interface StyleTarget {

// @public
export interface Subscriber {
// (undocumented)
handleChange(source: any, args: any): void;
}

// @public
export class SubscriberCollection implements Notifier {
// (undocumented)
notify(source: any, args: any): void;
export class SubscriberSet implements Notifier {
constructor(source: any);
has(subscriber: Subscriber): boolean;
notify(args: any): void;
// (undocumented)
readonly source: any;
subscribe(subscriber: Subscriber): void;
// (undocumented)
unsubscribe(subscriber: Subscriber): void;
}

Expand Down
14 changes: 12 additions & 2 deletions packages/web-components/fast-element/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ module.exports = function(config) {
'source-map-support',
'mocha',
],
plugins: [
require('karma-mocha'),
require('karma-mocha-reporter'),
require('karma-webpack'),
require('karma-source-map-support'),
require('karma-sourcemap-loader'),
require('karma-coverage-istanbul-reporter'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher')
],
files: [
`dist/esm/__test__/${setup}.js`,
],
preprocessors: {
[`dist/esm/__test__/${setup}.js`]: [
'webpack',
'sourcemap',
'webpack',
'sourcemap',
],
},
webpackMiddleware: {
Expand Down
6 changes: 3 additions & 3 deletions packages/web-components/fast-element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"prettier:diff": "prettier --config ../../../.prettierrc \"**/*.ts\" --list-different",
"eslint": "eslint . --ext .ts",
"eslint:fix": "eslint . --ext .ts --fix",
"test": "npm run test-node:verbose -- --experimental-modules",
"test-node": "mocha --reporter min --exit dist/esm/__test__/setup-node.js dist/esm/**/*.spec.js -- --experimental-modules",
"test-node:verbose": "mocha --reporter spec --exit dist/esm/__test__/setup-node.js dist/esm/**/*.spec.js -- --experimental-modules",
"test": "npm run test-node:verbose",
"test-node": "mocha --reporter min --exit dist/esm/__test__/setup-node.js './dist/esm/**/*.spec.js' -- --experimental-modules",
"test-node:verbose": "mocha --reporter spec --exit dist/esm/__test__/setup-node.js './dist/esm/**/*.spec.js' -- --experimental-modules",
"test-chrome": "karma start karma.conf.cjs --browsers=ChromeHeadlessOpt --single-run --coverage -- --experimental-modules",
"test-chrome:verbose": "karma start karma.conf.cjs --browsers=ChromeHeadlessOpt --single-run --coverage --reporter=mocha -- --experimental-modules",
"test-chrome:watch": "karma start karma.conf.cjs --browsers=ChromeHeadlessOpt --coverage --watch-extensions js -- --experimental-modules",
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/fast-element/src/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class AttributeDefinition implements Accessor {
source[this.callbackName](oldValue, newValue);
}

((source as any).$fastController as Notifier).notify(source, this.name);
((source as any).$fastController as Notifier).notify(this.name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/fast-element/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Controller extends PropertyChangeNotifier {
public readonly element: HTMLElement,
public readonly definition: FASTElementDefinition
) {
super();
super(element);

const template = definition.template;
const styles = definition.styles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DOM } from "../dom.js";
import { Observable } from "./observable.js";
import { SubscriberCollection } from "./notifier.js";
import { SubscriberSet } from "./notifier.js";
import {
calcSplices,
newSplice,
Expand Down Expand Up @@ -29,17 +29,15 @@ function adjustIndex(changeRecord: Splice, array: any[]): Splice {
return changeRecord;
}

export class ArrayObserver extends SubscriberCollection {
private collection: any[];
export class ArrayObserver extends SubscriberSet {
private oldCollection: any[] | undefined = void 0;
private splices: any[] | undefined = void 0;
private needsQueue: boolean = true;
call: () => void = this.flush;

constructor(collection: any[]) {
super();
(collection as any).$fastController = this;
this.collection = collection;
constructor(source: any[]) {
super(source);
(source as any).$fastController = this;
}

public addSplice(splice: Splice): void {
Expand Down Expand Up @@ -78,17 +76,17 @@ export class ArrayObserver extends SubscriberCollection {

const finalSplices =
oldCollection === void 0
? projectArraySplices(this.collection, splices!)
? projectArraySplices(this.source, splices!)
: calcSplices(
this.collection,
this.source,
0,
this.collection.length,
this.source.length,
oldCollection,
0,
oldCollection.length
);

this.notify(this, finalSplices);
this.notify(finalSplices);
}
}

Expand Down
Loading