Skip to content

Commit

Permalink
Merge pull request #415 from meteor/release-2.7
Browse files Browse the repository at this point in the history
Release 2.7
  • Loading branch information
Grubba27 authored May 23, 2023
2 parents 225ded2 + be8fdae commit 6ba5ed7
Show file tree
Hide file tree
Showing 22 changed files with 609 additions and 230 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v2.7.0, 2023-May-XX

* [#413](https://github.com/meteor/blaze/pull/413) Added support for Promises in Spacebars.call and Spacebars.dot.
* [#412](https://github.com/meteor/blaze/pull/412) Implemented async bindings in #let.

## v2.6.2, 2023-April-21

* [#403](https://github.com/meteor/blaze/pull/403) Add TS types to core
Expand Down
34 changes: 17 additions & 17 deletions packages/blaze/.versions
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[email protected]
[email protected].3
[email protected].4
[email protected]
[email protected]
[email protected]
blaze@2.6.2
blaze@2.7.0
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].0
[email protected].1
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].0
[email protected].1
[email protected]
[email protected].2
[email protected].6
[email protected].0
[email protected].3
[email protected].7
[email protected].1
[email protected]
[email protected]
[email protected]
Expand All @@ -28,28 +28,28 @@ [email protected]
[email protected]
[email protected]
[email protected]
local-test:blaze@2.6.2
local-test:blaze@2.7.0
[email protected]
[email protected].1
[email protected].2
[email protected].2
[email protected].3
[email protected]
[email protected]
[email protected]
[email protected].5
[email protected].6
[email protected]
[email protected]
[email protected]
npm-mongo@4.14.0
npm-mongo@4.16.0
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].6
[email protected].7
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].0
[email protected].1
[email protected]
[email protected]
[email protected]
Expand All @@ -58,7 +58,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected].1
[email protected].12
[email protected].4
[email protected].2
[email protected].13
[email protected].5
[email protected]
35 changes: 27 additions & 8 deletions packages/blaze/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,41 @@ Blaze.With = function (data, contentFunc) {
return view;
};


/**
* @summary Shallow compare of two bindings.
* @param {Binding} x
* @param {Binding} y
*/
function _isEqualBinding(x, y) {
return x && y ? x.error === y.error && x.value === y.value : x === y;
}

/**
* Attaches bindings to the instantiated view.
* @param {Object} bindings A dictionary of bindings, each binding name
* corresponds to a value or a function that will be reactively re-run.
* @param {View} view The target.
* @param {Blaze.View} view The target.
*/
Blaze._attachBindingsToView = function (bindings, view) {
function setBindingValue(name, value) {
if (value && typeof value.then === 'function') {
value.then(
value => view._scopeBindings[name].set({ value }),
error => view._scopeBindings[name].set({ error }),
);
} else {
view._scopeBindings[name].set({ value });
}
}

view.onViewCreated(function () {
Object.entries(bindings).forEach(function ([name, binding]) {
view._scopeBindings[name] = new ReactiveVar();
view._scopeBindings[name] = new ReactiveVar(undefined, _isEqualBinding);
if (typeof binding === 'function') {
view.autorun(function () {
view._scopeBindings[name].set(binding());
}, view.parentView);
view.autorun(() => setBindingValue(name, binding()), view.parentView);
} else {
view._scopeBindings[name].set(binding);
setBindingValue(name, binding);
}
});
});
Expand Down Expand Up @@ -149,7 +168,7 @@ Blaze.Each = function (argFunc, contentFunc, elseFunc) {

for (var i = from; i <= to; i++) {
var view = eachView._domrange.members[i].view;
view._scopeBindings['@index'].set(i);
view._scopeBindings['@index'].set({ value: i });
}
};

Expand Down Expand Up @@ -240,7 +259,7 @@ Blaze.Each = function (argFunc, contentFunc, elseFunc) {
itemView = eachView.initialSubviews[index];
}
if (eachView.variableName) {
itemView._scopeBindings[eachView.variableName].set(newItem);
itemView._scopeBindings[eachView.variableName].set({ value: newItem });
} else {
itemView.dataVar.set(newItem);
}
Expand Down
46 changes: 39 additions & 7 deletions packages/blaze/lookup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
import has from 'lodash.has';

Blaze._globalHelpers = {};
/** @param {(binding: Binding) => boolean} fn */
function _createBindingsHelper(fn) {
/** @param {string[]} names */
return (...names) => {
const view = Blaze.currentView;

// There's either zero arguments (i.e., check all bindings) or an additional
// "hash" argument that we have to ignore.
names = names.length === 0
// TODO: Should we walk up the bindings here?
? Object.keys(view._scopeBindings)
: names.slice(0, -1);

return names.some(name => {
const binding = _lexicalBindingLookup(view, name);
if (!binding) {
throw new Error(`Binding for "${name}" was not found.`);
}

return fn(binding.get());
});
};
}

Blaze._globalHelpers = {
/** @summary Check whether any of the given bindings (or all if none given) is still pending. */
'@pending': _createBindingsHelper(binding => binding === undefined),
/** @summary Check whether any of the given bindings (or all if none given) has rejected. */
'@rejected': _createBindingsHelper(binding => !!binding && 'error' in binding),
/** @summary Check whether any of the given bindings (or all if none given) has resolved. */
'@resolved': _createBindingsHelper(binding => !!binding && 'value' in binding),
};

// Documented as Template.registerHelper.
// This definition also provides back-compat for `UI.registerHelper`.
Expand Down Expand Up @@ -103,24 +134,25 @@ function _lexicalKeepGoing(currentView) {
return undefined;
}

Blaze._lexicalBindingLookup = function (view, name) {
function _lexicalBindingLookup(view, name) {
var currentView = view;
var blockHelpersStack = [];

// walk up the views stopping at a Spacebars.include or Template view that
// doesn't have an InOuterTemplateScope view as a parent
do {
// skip block helpers views
// if we found the binding on the scope, return it
if (has(currentView._scopeBindings, name)) {
var bindingReactiveVar = currentView._scopeBindings[name];
return function () {
return bindingReactiveVar.get();
};
return currentView._scopeBindings[name];
}
} while (currentView = _lexicalKeepGoing(currentView));

return null;
}

Blaze._lexicalBindingLookup = function (view, name) {
const binding = _lexicalBindingLookup(view, name);
return binding && (() => binding.get()?.value);
};

// templateInstance argument is provided to be available for possible
Expand Down
6 changes: 3 additions & 3 deletions packages/blaze/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'blaze',
summary: "Meteor Reactive Templating library",
version: '2.6.2',
version: '2.7.0',
git: 'https://github.com/meteor/blaze.git'
});

Expand All @@ -14,7 +14,7 @@ Npm.depends({

Package.onUse(function (api) {
api.use('[email protected] || 3.0.0', { weak: true }); // should be a weak dep, by having multiple "DOM backends"
api.use('tracker@1.2.0');
api.use('tracker@1.3.0');
api.use('[email protected]');
api.use('[email protected]');
api.use('[email protected]');
Expand Down Expand Up @@ -62,7 +62,7 @@ Package.onTest(function (api) {
api.use('[email protected]');
api.use('[email protected] || 3.0.0'); // strong dependency, for testing jQuery backend
api.use('[email protected]');
api.use('tracker@1.1.0');
api.use('tracker@1.3.0');

api.use('blaze');
api.use('[email protected]'); // for BlazeTools.toJS
Expand Down
15 changes: 15 additions & 0 deletions packages/blaze/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
/// general it's good for functions that create Views to set the name.
/// Views associated with templates have names of the form "Template.foo".

/**
* A binding is either `undefined` (pending), `{ error }` (rejected), or
* `{ value }` (resolved). Synchronous values are immediately resolved (i.e.,
* `{ value }` is used). The other states are reserved for asynchronous bindings
* (i.e., values wrapped with `Promise`s).
* @typedef {{ error: unknown } | { value: unknown } | undefined} Binding
*/

/**
* @class
* @summary Constructor for a View, which represents a reactive region of DOM.
Expand Down Expand Up @@ -81,6 +89,7 @@ Blaze.View = function (name, render) {
this._hasGeneratedParent = false;
// Bindings accessible to children views (via view.lookup('name')) within the
// closest template view.
/** @type {Record<string, ReactiveVar<Binding>>} */
this._scopeBindings = {};

this.renderCount = 0;
Expand Down Expand Up @@ -531,6 +540,12 @@ Blaze._isContentEqual = function (a, b) {
*/
Blaze.currentView = null;

/**
* @template T
* @param {Blaze.View} view
* @param {() => T} func
* @returns {T}
*/
Blaze._withCurrentView = function (view, func) {
var oldView = Blaze.currentView;
try {
Expand Down
76 changes: 38 additions & 38 deletions packages/observe-sequence/.versions
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
[email protected].0
babel-compiler@7.6.1
[email protected].0
[email protected].1
babel-compiler@7.10.4
[email protected].1
[email protected]
[email protected]
[email protected]
callback-hook@1.3.0
[email protected].1
[email protected].0
ddp-client@2.4.1
callback-hook@1.5.1
[email protected].2
[email protected].1
ddp-client@2.6.1
[email protected]
ddp-server@2.3.3
[email protected].1
dynamic-import@0.6.0
ecmascript@0.15.1
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.11.1
ecmascript-runtime-server@0.10.1
[email protected].1
[email protected].1
[email protected].10
ddp-server@2.6.1
[email protected].2
dynamic-import@0.7.3
ecmascript@0.16.7
ecmascript-runtime@0.8.1
ecmascript-runtime-client@0.12.1
ecmascript-runtime-server@0.11.0
[email protected].3
[email protected].3
[email protected].11
[email protected]
[email protected]
local-test:[email protected].19
logging@1.2.0
meteor@1.9.3
minimongo@1.6.2
[email protected].5
modules@0.16.0
modules-runtime@0.12.0
mongo@1.11.1
[email protected].2
local-test:[email protected].21
logging@1.3.2
meteor@1.11.2
minimongo@1.9.3
[email protected].9
modules@0.19.0
modules-runtime@0.13.1
mongo@1.16.6
[email protected].3
[email protected]
[email protected]
npm-mongo@3.9.0
[email protected].19
npm-mongo@4.16.0
[email protected].21
[email protected]
promise@0.11.2
[email protected].0
react-fast-refresh@0.1.1
promise@0.12.2
[email protected].1
react-fast-refresh@0.2.7
[email protected]
[email protected]
[email protected].0
socket-stream-client@0.3.3
tinytest@1.1.0
tracker@1.2.0
[email protected].10
webapp@1.10.1
[email protected].0
[email protected].1
socket-stream-client@0.5.1
tinytest@1.2.2
tracker@1.3.2
[email protected].13
webapp@1.13.5
[email protected].1
4 changes: 2 additions & 2 deletions packages/observe-sequence/package.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package.describe({
summary: "Observe changes to various sequence types such as arrays, cursors and objects",
version: "1.0.20"
version: "1.0.21"
});

Package.onUse(function (api) {
api.use('tracker@1.2.0');
api.use('tracker@1.3.0');
api.use('[email protected]'); // for idStringify
api.use('[email protected]');
api.use('[email protected]');
Expand Down
Loading

0 comments on commit 6ba5ed7

Please sign in to comment.