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

feat(wire-service): rfc implementation #166

Merged
merged 54 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d286bee
WIP
Mar 15, 2018
8b1dfc2
- Fix wire adapter callback names
Mar 16, 2018
9000634
- Add logic for prop change -> wire adapter updatedCallback
Mar 16, 2018
f5ae6e9
WIP - working on updated() callback hookup
Mar 16, 2018
7fee5b4
fix tslint errors
yungcheng Mar 16, 2018
f6aea16
wip: hook up updated
yungcheng Mar 16, 2018
4be7d46
delete wiring.ts
yungcheng Mar 19, 2018
551fbd2
only hook updated to bound props and clean up ServiceContext
yungcheng Mar 19, 2018
8ecb303
now everything in ServiceUpdateContext make sense
yungcheng Mar 19, 2018
873a280
fix playground setup
yungcheng Mar 19, 2018
05833f4
fix lifecycle hooks
yungcheng Mar 19, 2018
eef11f0
update todo-api
yungcheng Mar 19, 2018
2a13a36
fix single-wire-method and multiple wires in playground
yungcheng Mar 19, 2018
d4279f8
delete todo-legacy-api
yungcheng Mar 19, 2018
303f6a2
delete modules as they should be under lwc-integration
yungcheng Mar 19, 2018
df5356f
delete old jest tests
yungcheng Mar 19, 2018
1b50bfa
fix wire lwc-integration tests
yungcheng Mar 19, 2018
8a84e55
optimize building context
yungcheng Mar 19, 2018
c15dd48
refactor to buildContext
yungcheng Mar 19, 2018
18603ca
update type for buildContext
yungcheng Mar 19, 2018
ae06763
export unregister for non prod
yungcheng Mar 19, 2018
07a327c
add unit test
yungcheng Mar 19, 2018
83f6e98
refactor wiring internals
yungcheng Mar 20, 2018
112c99e
feat(wire-service): optimize serviceUpdateContext to have a prop to U…
yungcheng Mar 20, 2018
fab305d
fix(wire-service): lint error
yungcheng Mar 20, 2018
986a70c
build(wire-service): update file name to wire*.js and generate umd pr…
yungcheng Mar 21, 2018
b517417
chore(all): typo
yungcheng Mar 21, 2018
bba3915
feat(wire-service): address feedbacks
yungcheng Mar 21, 2018
25c519a
feat(wire-service): update impl based on latest proposal to use wired…
yungcheng Mar 23, 2018
2606fa7
fix(wire-service): update integration test
yungcheng Mar 23, 2018
da52252
refactor(wire): review feedback
caridy Mar 24, 2018
baf5daa
fix(wire-service): incorporate PR feedback
Mar 24, 2018
e249b23
WIP - rename vars for new terminology
Mar 24, 2018
458b307
refactor(wire-service): create a class for wiredEventTarget
yungcheng Mar 24, 2018
d1e0f67
refactor(wire-service): get rid off circular dependency
yungcheng Mar 24, 2018
218ac44
refactor(wire-service): Fix type bug between set and array
Mar 24, 2018
36f1682
refactor(wire-service): Extract engine-derived types into separate file
Mar 25, 2018
24878bb
fix(wire-service): Invoke wire adapter change handler once regardless…
Mar 25, 2018
7cf9db4
refactor(wire-service): move updatedFuture after updated
yungcheng Mar 25, 2018
a26ed12
fix(wire-service): update integration test
yungcheng Mar 25, 2018
b201fc1
refactor(wire-service): Move prop change tracking to property-trap. A…
Mar 26, 2018
81a3016
refactor(wire-service): rename callback to listener
yungcheng Mar 26, 2018
0e5dbd1
feat(wire-service): check for WireContextEvent
yungcheng Mar 26, 2018
6767eb1
feat(wire-service): add wiring jest tests
yungcheng Mar 26, 2018
d7623ff
refactor(wire-service): use jest mock fn for mockInstallTrap
yungcheng Mar 26, 2018
4812f30
feat(wire-service): add jest test for register
yungcheng Mar 26, 2018
1ee0796
test(wire-service): property-trap test cases
Mar 26, 2018
a42f70a
refactor(wire-service): use jest.fn() instead of handroll function
yungcheng Mar 26, 2018
d922d93
refactor(wire-service): use forEach instead of for...of for better co…
yungcheng Mar 26, 2018
d2ee1c6
feat(wire-service): add a test case to capture multiple components (c…
yungcheng Mar 26, 2018
bd00213
Merge branch 'wire-rfc-impl' of github.com:salesforce/lwc into releas…
yungcheng Mar 26, 2018
abc8aca
refactor(wire-service): fix lint errors
yungcheng Mar 26, 2018
d234b6a
feat(wire-service): merge master in
yungcheng Mar 26, 2018
f85f8c9
build(wire-service): update module artifact name
yungcheng Mar 26, 2018
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
6 changes: 6 additions & 0 deletions bin/generate-aura-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ cp ./packages/lwc-engine/dist/umd/es5/engine.js $AURA_FILEPATH/aura-resources/s
cp ./packages/lwc-engine/dist/umd/es5/engine_debug.js $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/engine/engine_compat_debug.js
cp ./packages/lwc-engine/dist/umd/es5/engine.min.js $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/engine/engine_compat.min.js

# wire service
cp ./packages/lwc-wire-service/dist/umd/es2017/wire* $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/wire/
cp ./packages/lwc-wire-service/dist/umd/es5/wire.js $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/wire/wire_compat.js
cp ./packages/lwc-wire-service/dist/umd/es5/wire_debug.js $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/wire/wire_compat_debug.js
cp ./packages/lwc-wire-service/dist/umd/es5/wire.min.js $AURA_FILEPATH/aura-resources/src/main/resources/aura/resources/wire/wire_compat.min.js

# compiler
cp ./packages/lwc-compiler/dist/umd/compiler.js $AURA_FILEPATH/aura-modules/src/main/resources/modules/compiler.js

Expand Down
7 changes: 1 addition & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ module.exports = {
'<rootDir>/packages/*/**/__tests__/*.spec.(js|ts)'
],
projects: [
'<rootDir>',
'<rootDir>/packages/*/jest.config.js'
],
testPathIgnorePatterns: [
'node_modules',
'lwc-wire-service'
'<rootDir>'
]
};
4 changes: 2 additions & 2 deletions packages/lwc-integration/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mode = process.env.MODE || 'compat';
const isCompat = /compat/.test(mode);

const engineModeFile = path.join(require.resolve(`lwc-engine/dist/umd/${isCompat ? 'es5': 'es2017'}/engine.js`));
const wireServicePath = path.join(require.resolve(`lwc-wire-service/dist/umd/${isCompat ? 'es5': 'es2017'}/wire-service.js`));
const wireServicePath = path.join(require.resolve(`lwc-wire-service/dist/umd/${isCompat ? 'es5': 'es2017'}/wire.js`));
const todoPath = path.join(require.resolve('../src/shared/todo.js'));

const testSufix = '.test.js';
Expand Down Expand Up @@ -117,7 +117,7 @@ fs.copySync(engineModeFile, path.join(testSharedOutput,'engine.js'));
fs.writeFileSync(path.join(testSharedOutput,'downgrade.js'), compatPolyfills.loadDowngrade());
fs.writeFileSync(path.join(testSharedOutput,'polyfills.js'), compatPolyfills.loadPolyfills());

fs.copySync(wireServicePath, path.join(testSharedOutput, 'wire-service.js'));
fs.copySync(wireServicePath, path.join(testSharedOutput, 'wire.js'));
fs.copySync(todoPath, path.join(testSharedOutput, 'todo.js'));

// -- Build component tests -----------------------------------------------------=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Element, api, track, wire } from 'engine';
import { serviceTodo } from 'todo';
import { getTodo } from 'todo';

export default class WiredMethod extends Element {
@api todoId;
@track state = { error: undefined, todo: undefined };

@wire(serviceTodo, { id: '$todoId' })
function(error, data) {
@wire(getTodo, { id: '$todoId' })
function({error, data}) {
this.state = { error: error, todo: data };
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Element, api, wire } from 'engine';
import { serviceTodo } from 'todo';
import { getTodo } from 'todo';
export default class WiredProp extends Element {
@api todoId;

@wire(serviceTodo, { id: '$todoId' })
@wire(getTodo, { id: '$todoId' })
todo;

get error() {
Expand Down
41 changes: 35 additions & 6 deletions packages/lwc-integration/src/shared/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,44 @@ exports.app = function (cmpName) {

exports.todoApp = function (cmpName) {
return `
import { serviceTodo } from 'todo';
import registerWireService from 'wire-service';
import { registerWireService, register as registerAdapter, ValueChangedEvent } from 'wire-service';
import { createElement, register } from 'engine';
import Cmp from '${cmpName}';
import { getTodo, getObservable } from 'todo';

registerWireService(register, function () {
return {
serviceTodo
registerWireService(register);

// Register the wire adapter for @wire(getTodo).
registerAdapter(getTodo, function getTodoWireAdapter(wiredEventTarget) {
let subscription;
let config;
wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data: undefined, error: undefined }));
const observer = {
next: data => wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data, error: undefined })),
error: error => wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data: undefined, error }))
};
wiredEventTarget.addEventListener('connect', () => {
const observable = getObservable(config);
if (observable) {
subscription = observable.subscribe(observer);
return;
}
});
wiredEventTarget.addEventListener('disconnect', () => {
subscription.unsubscribe();
});
wiredEventTarget.addEventListener('config', (newConfig) => {
config = newConfig;
if (subscription) {
subscription.unsubscribe();
subscription = undefined;
}
const observable = getObservable(config);
if (observable) {
subscription = observable.subscribe(observer);
return;
}
});
});

const element = createElement('${cmpName}', { is: Cmp });
Expand Down Expand Up @@ -57,7 +86,7 @@ exports.wireServiceHtml = function (cmpName, isCompat) {
${isCompat ? COMPAT : ''}
<script src="../../shared/engine.js"></script>
<script src="../../shared/todo.js"></script>
<script src="../../shared/wire-service.js"></script>
<script src="../../shared/wire.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this point to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below about file name of wire.js vs wire-service.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll be a copy from the lwc-wire-service dist, I changed the filename from wire-service.js to wire.js for easier release through Aura. That's why I need to change it here.

<script src="./${cmpName}.js"></script>
</body>
</html>
Expand Down
129 changes: 66 additions & 63 deletions packages/lwc-integration/src/shared/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,84 @@
}(this, (function (exports) {
'use strict';

function getSubject(initialValue, initialError) {
var observer;
function getSubject(initialValue, initialError) {
var observer;

function next(value) {
observer.next(value);
}
function next(value) {
observer.next(value);
}

function error(err) {
observer.error(err);
}
function error(err) {
observer.error(err);
}

function complete() {
observer.complete();
}
function complete() {
observer.complete();
}

var observable = {
subscribe: function(obs) {
observer = obs;
if (initialValue) {
next(initialValue);
}
if (initialError) {
error(initialError);
var observable = {
subscribe: function(obs) {
observer = obs;
if (initialValue) {
next(initialValue);
}
if (initialError) {
error(initialError);
}
return {
unsubscribe: function() {}
};
}
return {
unsubscribe: function() {}
};
}
};
};

return {
next: next,
error: error,
complete: complete,
observable: observable
};
}
return {
next: next,
error: error,
complete: complete,
observable: observable
};
}

function generateTodo(id, completed) {
return {
id: id,
title: 'task ' + id,
completed: completed
};
}
function generateTodo(id, completed) {
return {
id: id,
title: 'task ' + id,
completed: completed
};
}

var TODO = [
generateTodo(0, true),
generateTodo(1, false),
// intentionally skip 2
generateTodo(3, true),
generateTodo(4, true),
// intentionally skip 5
generateTodo(6, false),
generateTodo(7, false)
].reduce(function(acc, value) {
acc[value.id] = value;
return acc;
}, {});
var TODO = [
generateTodo(0, true),
generateTodo(1, false),
// intentionally skip 2
generateTodo(3, true),
generateTodo(4, true),
// intentionally skip 5
generateTodo(6, false),
generateTodo(7, false)
].reduce(function(acc, value) {
acc[value.id] = value;
return acc;
}, {});


function serviceTodo(config) {
if (!('id' in config)) {
return undefined;
}
function getObservable(config) {
if (!config || !('id' in config)) {
return undefined;
}

var todo = TODO[config.id];
if (!todo) {
var subject = getSubject(undefined, { message: 'Todo not found' });
return subject.observable;
}

var todo = TODO[config.id];
if (!todo) {
var subject = getSubject(undefined, { message: 'Todo not found' });
return subject.observable;
return getSubject(todo).observable;
}

return getSubject(todo).observable;
}
const getTodo = Symbol('getTodo');

exports.serviceTodo = serviceTodo;
exports.getTodo = getTodo;
exports.getObservable = getObservable;
Object.defineProperty(exports, '__esModule', { value: true });
})));
})));
22 changes: 0 additions & 22 deletions packages/lwc-wire-service/jest.config.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/lwc-wire-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "lwc-wire-service",
"version": "0.18.1",
"description": "@wire service",
"main": "dist/commonjs/es2017/wire-service.js",
"module": "dist/modules/es2017/wire-service.js",
"main": "dist/commonjs/es2017/wire.js",
"module": "dist/modules/es2017/wire.js",
"scripts": {
"build": "concurrently \"yarn build:es-and-cjs\" \"yarn build:umd:dev\" \"yarn build:umd:prod\"",
"clean": "rm -rf dist",
"lint": "eslint src playground",
"build": "concurrently \"yarn build:es-and-cjs\" \"yarn build:umd:dev\"",
"build:umd:dev": "rollup -c rollup.config.umd.dev.js",
"build:umd:prod": "rollup -c rollup.config.umd.prod.js",
"build:es-and-cjs": "rollup -c rollup.config.es-and-cjs.js",
"build:playground": "rollup -c playground/rollup.config.js",
"serve": "node playground/server.js",
Expand All @@ -34,7 +34,7 @@
},
"lwc": {
"modules": {
"wire-service": "dist/modules/es2017/wire-service.js"
"wire-service": "dist/modules/es2017/wire.js"
}
}
}
4 changes: 2 additions & 2 deletions packages/lwc-wire-service/playground/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// bootstrapping process for App
import { createElement, register } from 'engine';
import { registerWireService } from 'wire-service';
import App from 'x-demo';

import registerPlaygroundWireAdapters from 'x-wire-adapter';

registerPlaygroundWireAdapters({register});
registerWireService(register);

const container = document.getElementById('main');
const element = createElement('x-demo', { is: App });
Expand Down
2 changes: 1 addition & 1 deletion packages/lwc-wire-service/playground/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function resolver() {
resolveId: (id) => {
// wire service itself (no namespace)
if (id === 'wire-service') {
return path.resolve('./src/main.js');
return require.resolve('lwc-wire-service').replace('commonjs', 'modules');
} else if (id === 'engine') {
return require.resolve('lwc-engine').replace('commonjs', 'modules');
// test and wire namespace components
Expand Down
2 changes: 2 additions & 0 deletions packages/lwc-wire-service/playground/x/demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ <h1>Demo of @wire</h1>
<h2>Component with single @wire bound to field</h2>
<x-single-wire todo-id={state.todoId}></x-single-wire>
<hr>

<h2>Component with single @wire bound to method</h2>
<x-single-wire-method todo-id={state.todoId}></x-single-wire-method>
<hr>
<h2>Component with multiple @wires driven by non-@api properties</h2>
<x-multiple-wires todo-id={state.todoId}></x-multiple-wires>

</template>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Element, api, wire } from 'engine';
import { getTodo } from 'x-todo-api';

export default class MultipleWires extends Element {
idA;
Expand All @@ -18,10 +19,10 @@ export default class MultipleWires extends Element {
return this.idA;
}

@wire('todo', { id: '$idA' })
@wire(getTodo, { id: '$idA' })
todoA;

@wire('todo', { id: '$idB' })
@wire(getTodo, { id: '$idB' })
todoB;

get hasError() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Element, api, wire, track } from 'engine';
import { getTodo } from 'x-todo-api';

export default class SingleWireMethod extends Element {
@api todoId;

@track error = undefined;
@track todo = undefined;

@wire('todo', { id: '$todoId' })
function(error, data) {
@wire(getTodo, { id: '$todoId' })
function({error, data}) {
this.error = error;
this.todo = data;
}
Expand Down
Loading