Skip to content

Commit

Permalink
Merge pull request #418 from meteor/fix-async-nested-reactivity
Browse files Browse the repository at this point in the history
Fix reactivity for non-primitives
  • Loading branch information
jankapunkt committed May 27, 2023
2 parents 6ba5ed7 + 93219df commit 34b8f89
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
7 changes: 6 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## v2.7.0, 2023-May-XX
## v2.7.1, 2023-May-26

* [#413](https://github.com/meteor/blaze/pull/418) Fix reactivity for non-primitives.


## v2.7.0, 2023-May-23

* [#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.
Expand Down
4 changes: 2 additions & 2 deletions packages/blaze/.versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ babel-compiler@7.10.4
babel-runtime@1.5.1
base64@1.0.12
binary-heap@1.0.11
blaze@2.7.0
blaze@2.7.1
blaze-tools@1.1.3
boilerplate-generator@1.7.1
caching-compiler@1.2.2
Expand All @@ -28,7 +28,7 @@ htmljs@1.1.1
id-map@1.1.1
inter-process-messaging@0.1.1
jquery@1.11.10
local-test:blaze@2.7.0
local-test:blaze@2.7.1
logging@1.3.2
meteor@1.11.2
minimongo@1.9.3
Expand Down
22 changes: 16 additions & 6 deletions packages/blaze/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Blaze._calculateCondition = function (cond) {
/**
* @summary Constructs a View that renders content with a data context.
* @locus Client
* @param {Object|Function} data An object to use as the data context, or a function returning such an object. If a function is provided, it will be reactively re-run.
* @param {Object|Function} data An object to use as the data context, or a function returning such an object. If a
* function is provided, it will be reactively re-run.
* @param {Function} contentFunc A Function that returns [*renderable content*](#Renderable-Content).
*/
Blaze.With = function (data, contentFunc) {
Expand Down Expand Up @@ -39,7 +40,12 @@ Blaze.With = function (data, contentFunc) {
* @param {Binding} y
*/
function _isEqualBinding(x, y) {
return x && y ? x.error === y.error && x.value === y.value : x === y;
if (typeof x === 'object' && typeof y === 'object') {
return x.error === y.error && ReactiveVar._isEqual(x.value, y.value);
}
else {
return ReactiveVar._isEqual(x, y);
}
}

/**
Expand Down Expand Up @@ -88,9 +94,11 @@ Blaze.Let = function (bindings, contentFunc) {
/**
* @summary Constructs a View that renders content conditionally.
* @locus Client
* @param {Function} conditionFunc A function to reactively re-run. Whether the result is truthy or falsy determines whether `contentFunc` or `elseFunc` is shown. An empty array is considered falsy.
* @param {Function} conditionFunc A function to reactively re-run. Whether the result is truthy or falsy determines
* whether `contentFunc` or `elseFunc` is shown. An empty array is considered falsy.
* @param {Function} contentFunc A Function that returns [*renderable content*](#Renderable-Content).
* @param {Function} [elseFunc] Optional. A Function that returns [*renderable content*](#Renderable-Content). If no `elseFunc` is supplied, no content is shown in the "else" case.
* @param {Function} [elseFunc] Optional. A Function that returns [*renderable content*](#Renderable-Content). If no
* `elseFunc` is supplied, no content is shown in the "else" case.
*/
Blaze.If = function (conditionFunc, contentFunc, elseFunc, _not) {
var conditionVar = new ReactiveVar;
Expand All @@ -113,9 +121,11 @@ Blaze.If = function (conditionFunc, contentFunc, elseFunc, _not) {
/**
* @summary An inverted [`Blaze.If`](#Blaze-If).
* @locus Client
* @param {Function} conditionFunc A function to reactively re-run. If the result is falsy, `contentFunc` is shown, otherwise `elseFunc` is shown. An empty array is considered falsy.
* @param {Function} conditionFunc A function to reactively re-run. If the result is falsy, `contentFunc` is shown,
* otherwise `elseFunc` is shown. An empty array is considered falsy.
* @param {Function} contentFunc A Function that returns [*renderable content*](#Renderable-Content).
* @param {Function} [elseFunc] Optional. A Function that returns [*renderable content*](#Renderable-Content). If no `elseFunc` is supplied, no content is shown in the "else" case.
* @param {Function} [elseFunc] Optional. A Function that returns [*renderable content*](#Renderable-Content). If no
* `elseFunc` is supplied, no content is shown in the "else" case.
*/
Blaze.Unless = function (conditionFunc, contentFunc, elseFunc) {
return Blaze.If(conditionFunc, contentFunc, elseFunc, true /*_not*/);
Expand Down
2 changes: 1 addition & 1 deletion 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.7.0',
version: '2.7.1',
git: 'https://github.com/meteor/blaze.git'
});

Expand Down
6 changes: 3 additions & 3 deletions packages/spacebars/.versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ babel-compiler@7.10.4
babel-runtime@1.5.1
base64@1.0.12
binary-heap@1.0.11
blaze@2.7.0
blaze@2.7.1
boilerplate-generator@1.7.1
callback-hook@1.5.1
check@1.3.2
Expand All @@ -23,7 +23,7 @@ geojson-utils@1.0.11
htmljs@1.1.1
id-map@1.1.1
inter-process-messaging@0.1.1
local-test:spacebars@1.4.0
local-test:spacebars@1.4.1
logging@1.3.2
meteor@1.11.2
minimongo@1.9.3
Expand All @@ -45,7 +45,7 @@ reload@1.3.1
retry@1.1.0
routepolicy@1.1.1
socket-stream-client@0.5.1
spacebars@1.4.0
spacebars@1.4.1
tinytest@1.2.2
tracker@1.3.2
underscore@1.0.13
Expand Down
4 changes: 2 additions & 2 deletions packages/spacebars/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'spacebars',
summary: "Handlebars-like template language for Meteor",
version: '1.4.0',
version: '1.4.1',
git: 'https://github.com/meteor/blaze.git'
});

Expand All @@ -20,7 +20,7 @@ Package.onUse(function (api) {
api.export('Spacebars');

api.use('htmljs@1.1.1');
api.use('blaze@2.7.0');
api.use('blaze@2.7.1');

api.addFiles([
'spacebars-runtime.js'
Expand Down
8 changes: 5 additions & 3 deletions packages/spacebars/spacebars-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Spacebars.makeRaw = function (value) {
};

/***
* @sumamry Executes `fn` with the resolved value of `promise` while preserving
* @summary Executes `fn` with the resolved value of `promise` while preserving
* the context, i.e., `Blaze.currentView` and `Tracker.currentComputation`.
* @template T
* @template U
Expand Down Expand Up @@ -157,7 +157,7 @@ Spacebars.call = function (value/*, args*/) {
for (var i = 1; i < arguments.length; i++) {
var arg = arguments[i];
newArgs[i-1] = (typeof arg === 'function' ? arg() : arg);
anyIsPromise = anyIsPromise || newArgs[i-1] instanceof Promise;
anyIsPromise = anyIsPromise || isPromiseLike(newArgs[i-1]);
}

if (anyIsPromise) {
Expand All @@ -173,6 +173,8 @@ Spacebars.call = function (value/*, args*/) {
}
};

const isPromiseLike = x => typeof x?.then === 'function';

// Call this as `Spacebars.kw({ ... })`. The return value
// is `instanceof Spacebars.kw`.
Spacebars.kw = function (hash) {
Expand Down Expand Up @@ -235,7 +237,7 @@ Spacebars.dot = function (value, id1/*, id2, ...*/) {
if (! value)
return value; // falsy, don't index, pass through

if (value && typeof value.then === 'function')
if (isPromiseLike(value))
return _thenWithContext(value, value => Spacebars.dot(value, id1));

var result = value[id1];
Expand Down

0 comments on commit 34b8f89

Please sign in to comment.