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

Feature/async blaze #409

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions async-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
19 changes: 19 additions & 0 deletions async-test/.meteor/.finished-upgraders
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file contains information which helps Meteor properly upgrade your
# app when you run 'meteor update'. You should check it into version control
# with your project.

notices-for-0.9.0
notices-for-0.9.1
0.9.4-platform-file
notices-for-facebook-graph-api-2
1.2.0-standard-minifiers-package
1.2.0-meteor-platform-split
1.2.0-cordova-changes
1.2.0-breaking-changes
1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package
1.4.3-split-account-service-packages
1.5-add-dynamic-import-package
1.7-split-underscore-from-meteor-base
1.8.3-split-jquery-from-blaze
1 change: 1 addition & 0 deletions async-test/.meteor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
7 changes: 7 additions & 0 deletions async-test/.meteor/.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file contains a token that is unique to your project.
# Check it into your repository along with the rest of this directory.
# It can be used for purposes such as:
# - ensuring you don't accidentally deploy one app on top of another
# - providing package authors with aggregated statistics

fndz7jriz9hm.ql6y6jjkk02q
25 changes: 25 additions & 0 deletions async-test/.meteor/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-base@1.5.1 # Packages every Meteor app needs to have
mobile-experience@1.1.0 # Packages for a great mobile UX
mongo@1.16.5 # The database Meteor supports right now
blaze-html-templates # Compile .html files into Meteor Blaze views
jquery # Wrapper package for npm-installed jquery
reactive-var@1.0.12 # Reactive variable for tracker
tracker@1.3.1 # Meteor's client-side reactive programming library

standard-minifier-css@1.9.0 # CSS minifier run for production mode
standard-minifier-js@2.8.1 # JS minifier run for production mode
es5-shim@4.8.0 # ECMAScript 5 compatibility for older browsers
ecmascript@0.16.6 # Enable ECMAScript2015+ syntax in app code
typescript@4.9.4 # Enable TypeScript syntax in .ts and .tsx modules
shell-server@0.5.0 # Server-side component of the `meteor shell` command



hot-module-replacement@0.5.2 # Update code in development without reloading the page
blaze-hot # Update files using Blaze's API with HMR
2 changes: 2 additions & 0 deletions async-test/.meteor/platforms
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server
browser
1 change: 1 addition & 0 deletions async-test/.meteor/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
METEOR@2.11.0
78 changes: 78 additions & 0 deletions async-test/.meteor/versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
allow-deny@1.1.1
autoupdate@1.8.0
babel-compiler@7.10.3
babel-runtime@1.5.1
base64@1.0.12
binary-heap@1.0.11
blaze@2.6.2
blaze-hot@1.1.1
blaze-html-templates@2.0.0
blaze-tools@1.1.3
boilerplate-generator@1.7.1
caching-compiler@1.2.2
caching-html-compiler@1.2.1
callback-hook@1.5.0
check@1.3.2
ddp@1.4.1
ddp-client@2.6.1
ddp-common@1.4.0
ddp-server@2.6.0
diff-sequence@1.1.2
dynamic-import@0.7.2
ecmascript@0.16.6
ecmascript-runtime@0.8.0
ecmascript-runtime-client@0.12.1
ecmascript-runtime-server@0.11.0
ejson@1.1.3
es5-shim@4.8.0
fetch@0.1.3
geojson-utils@1.0.11
hot-code-push@1.0.4
hot-module-replacement@0.5.2
html-tools@1.1.3
htmljs@1.1.1
id-map@1.1.1
inter-process-messaging@0.1.1
jquery@3.0.0
launch-screen@1.3.0
logging@1.3.2
meteor@1.11.1
meteor-base@1.5.1
minifier-css@1.6.2
minifier-js@2.7.5
minimongo@1.9.2
mobile-experience@1.1.0
mobile-status-bar@1.1.0
modern-browsers@0.1.9
modules@0.19.0
modules-runtime@0.13.1
modules-runtime-hot@0.14.1
mongo@1.16.5
mongo-decimal@0.1.3
mongo-dev-server@1.1.0
mongo-id@1.0.8
npm-mongo@4.14.0
observe-sequence@1.0.20
ordered-dict@1.1.0
promise@0.12.2
random@1.2.1
react-fast-refresh@0.2.6
reactive-var@1.0.12
reload@1.3.1
retry@1.1.0
routepolicy@1.1.1
shell-server@0.5.0
socket-stream-client@0.5.0
spacebars@1.3.0
spacebars-compiler@1.3.1
standard-minifier-css@1.9.0
standard-minifier-js@2.8.1
templating@1.4.2
templating-compiler@1.4.1
templating-runtime@1.6.1
templating-tools@1.2.2
tracker@1.3.1
typescript@4.9.4
underscore@1.0.12
webapp@1.13.4
webapp-hashing@1.1.1
4 changes: 4 additions & 0 deletions async-test/client/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body,
pre {
margin: 0;
}
77 changes: 77 additions & 0 deletions async-test/client/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<head>
<title>async-test</title>
</head>

<body>
{{> example}}
</body>

<template name="example">
<pre>
Cursors.
1. #each, cursorGetterSync: {{#each cursorGetterSync }}{{#if @index}} - {{/if}}{{_id}}{{/each}}
2. #each, cursorValueSync: {{#each cursorValueSync }}{{#if @index}} - {{/if}}{{_id}}{{/each}}
{{!-- #each expects an array or cursor. --}}
3. {{!-- #each, cursorGetterAsync: {{#each cursorGetterAsync}}{{#if @index}} - {{/if}}{{_id}}{{/each}} --}}
4. {{!-- #each, cursorValueAsync: {{#each cursorValueAsync }}{{#if @index}} - {{/if}}{{_id}}{{/each}} --}}
{{!-- #eachAwait does not exist yet. --}}
5. {{!-- #eachAwait, cursorGetterAsync: {{#eachAwait cursorGetterAsync}}{{#if @index}} - {{/if}}{{_id}}{{/eachAwait}} --}}
6. {{!-- #eachAwait, cursorGetterSync: {{#eachAwait cursorGetterSync }}{{#if @index}} - {{/if}}{{_id}}{{/eachAwait}} --}}
7. {{!-- #eachAwait, cursorValueAsync: {{#eachAwait cursorValueAsync }}{{#if @index}} - {{/if}}{{_id}}{{/eachAwait}} --}}
8. {{!-- #eachAwait, cursorValueSync: {{#eachAwait cursorValueSync }}{{#if @index}} - {{/if}}{{_id}}{{/eachAwait}} --}}

Primitives.
1. #let, primitiveGetterAsync: {{#let x=primitiveGetterAsync}}{{x}}{{/let}}
2. #let, primitiveGetterSync: {{#let x=primitiveGetterSync }}{{x}}{{/let}}
3. #let, primitiveValueAsync: {{#let x=primitiveValueAsync }}{{x}}{{/let}}
4. #let, primitiveValueSync: {{#let x=primitiveValueSync }}{{x}}{{/let}}
5. #letAwait, primitiveGetterAsync: {{#letAwait x=primitiveGetterAsync}}{{x}}{{/letAwait}}
6. #letAwait, primitiveGetterSync: {{#letAwait x=primitiveGetterSync }}{{x}}{{/letAwait}}
7. #letAwait, primitiveValueAsync: {{#letAwait x=primitiveValueAsync }}{{x}}{{/letAwait}}
8. #letAwait, primitiveValueSync: {{#letAwait x=primitiveValueSync }}{{x}}{{/letAwait}}

Objects (inner accessors).
1. #let, asyncObjectAsyncProperty: {{#let x=asyncObjectAsyncProperty}}{{x.foo}}{{/let}}
2. #let, asyncObjectSyncProperty: {{#let x=asyncObjectSyncProperty }}{{x.foo}}{{/let}}
3. #let, syncObjectAsyncProperty: {{#let x=syncObjectAsyncProperty }}{{x.foo}}{{/let}}
4. #let, syncObjectSyncProperty: {{#let x=syncObjectSyncProperty }}{{x.foo}}{{/let}}
5. #letAwait, asyncObjectAsyncProperty: {{#letAwait x=asyncObjectAsyncProperty}}{{x.foo}}{{/letAwait}}
6. #letAwait, asyncObjectSyncProperty: {{#letAwait x=asyncObjectSyncProperty }}{{x.foo}}{{/letAwait}}
7. #letAwait, syncObjectAsyncProperty: {{#letAwait x=syncObjectAsyncProperty }}{{x.foo}}{{/letAwait}}
8. #letAwait, syncObjectSyncProperty: {{#letAwait x=syncObjectSyncProperty }}{{x.foo}}{{/letAwait}}

Objects (outer accessors).
1. #let, asyncObjectAsyncProperty: {{#let x=asyncObjectAsyncProperty.foo}}{{x}}{{/let}}
2. #let, asyncObjectSyncProperty: {{#let x=asyncObjectSyncProperty.foo }}{{x}}{{/let}}
3. #let, syncObjectAsyncProperty: {{#let x=syncObjectAsyncProperty.foo }}{{x}}{{/let}}
4. #let, syncObjectSyncProperty: {{#let x=syncObjectSyncProperty.foo }}{{x}}{{/let}}
5. #letAwait, asyncObjectAsyncProperty: {{#letAwait x=asyncObjectAsyncProperty.foo}}{{x}}{{/letAwait}}
6. #letAwait, asyncObjectSyncProperty: {{#letAwait x=asyncObjectSyncProperty.foo }}{{x}}{{/letAwait}}
7. #letAwait, syncObjectAsyncProperty: {{#letAwait x=syncObjectAsyncProperty.foo }}{{x}}{{/letAwait}}
8. #letAwait, syncObjectSyncProperty: {{#letAwait x=syncObjectSyncProperty.foo }}{{x}}{{/letAwait}}

Non-ideal states of #letAwait (single).
1. (D) {{#letAwait x=delayed }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}}{{/if}}{{/if}}{{/letAwait}}
2. (P) {{#letAwait x=pending }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}}{{/if}}{{/if}}{{/letAwait}}
3. (R) {{#letAwait x=rejected}}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}}{{/if}}{{/if}}{{/letAwait}}

Non-ideal states of #letAwait (multiple).
1. (DD) {{#letAwait x=delayed y=delayed }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
2. (DP) {{#letAwait x=delayed y=pending }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
3. (DR) {{#letAwait x=delayed y=rejected}}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
4. (PD) {{#letAwait x=pending y=delayed }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
5. (PP) {{#letAwait x=pending y=pending }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
6. (PR) {{#letAwait x=pending y=rejected}}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
7. (RD) {{#letAwait x=rejected y=delayed }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
8. (RP) {{#letAwait x=rejected y=pending }}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}
9. (RR) {{#letAwait x=rejected y=rejected}}{{#if __async_state__.error}}Rejected: {{__async_state__.error}}{{else}}{{#if __async_state__.pending}}Pending{{else}}Resolved: {{x}} - {{y}}{{/if}}{{/if}}{{/letAwait}}

{{!-- This would require adjusting the parser and the AST. This is doable, though touches a lot of parts.
{{#letAwait x=async}}
{{SOME_KEYWORD_THAT_INDICATES_PENDING_BLOCK}}Pending
{{SOME_KEYWORD_THAT_INDICATES_REJECTED_BLOCK}}Rejected: {{SOME_KEYWORD_THAT_INDICATES_REJECTION}}
{{SOME_KEYWORD_THAT_INDICATES_RESOLVED_BLOCK}}Resolved: {{x}}
{{/letAwait}}
--}}
</pre>
</template>
35 changes: 35 additions & 0 deletions async-test/client/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Mongo } from 'meteor/mongo';
import { Random } from 'meteor/random';
import { Template } from 'meteor/templating';

import './main.html';

const Collection = new Mongo.Collection(null);
Collection.insertAsync({});
Collection.insertAsync({});
Collection.insertAsync({});

Template.example.helpers({
// Cursors.
cursorGetterAsync: () => Promise.resolve(Collection.find()),
cursorGetterSync: () => Collection.find(),
cursorValueAsync: Promise.resolve(Collection.find()),
cursorValueSync: Collection.find(),

// Primitives.
primitiveGetterAsync: () => Promise.resolve(Random.id()),
primitiveGetterSync: () => Random.id(),
primitiveValueAsync: Promise.resolve(Random.id()),
primitiveValueSync: Random.id(),

// Objects.
asyncObjectAsyncProperty: Promise.resolve({ foo: Promise.resolve(Random.id()) }),
asyncObjectSyncProperty: Promise.resolve({ foo: Random.id() }),
syncObjectAsyncProperty: { foo: Promise.resolve(Random.id()) },
syncObjectSyncProperty: { foo: Random.id() },

// Non-ideal states of #letAwait.
delayed: new Promise(resolve => setTimeout(() => resolve(Random.id()), 1000)),
pending: new Promise(() => {}),
rejected: Promise.reject(Random.id()),
});
23 changes: 23 additions & 0 deletions async-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "async-test",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer",
"setup": "ln -sfn ../packages ./packages"
},
"dependencies": {
"@babel/runtime": "^7.17.9",
"jquery": "^3.6.0",
"meteor-node-stubs": "^1.2.1"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests/main.js"
}
}
1 change: 1 addition & 0 deletions async-test/packages
5 changes: 5 additions & 0 deletions async-test/server/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Meteor } from "meteor/meteor";

Meteor.startup(() => {
// code to run on server at startup
});
20 changes: 20 additions & 0 deletions async-test/tests/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from "assert";

describe("async-test", function () {
it("package.json has correct name", async function () {
const { name } = await import("../package.json");
assert.strictEqual(name, "async-test");
});

if (Meteor.isClient) {
it("client is not server", function () {
assert.strictEqual(Meteor.isServer, false);
});
}

if (Meteor.isServer) {
it("server is not client", function () {
assert.strictEqual(Meteor.isClient, false);
});
}
});
Loading