跳至内容

重命名函数

在 v3 中,我们决定重命名一些函数,以使其 API 更一致。

  • Accounts.setPassword
  • Assets.getText
  • Assets.getBinary

Accounts.setPassword

它不再可用,您应该使用 Accounts.setPasswordAsync

javascript

// Before

function someFunction(userId, newPassword) {
  Accounts.setPassword(userId, newPassword);
}

// After

async function someFunction(userId, newPassword) {
  await Accounts.setPasswordAsync(userId, newPassword);
}

Assets.getText

它不再可用,您应该使用 Assets.getTextAsync

javascript

// Before

function someFunction() {
  const text = Assets.getText('some-file.txt');
  return text;
}

// After

async function someFunction() {
  const text = await Assets.getTextAsync('some-file.txt');
  return text;
}

Assets.getBinary

它不再可用,您应该使用 Assets.getBinaryAsync

javascript

// Before

function someFunction() {
  const binary = Assets.getBinary('some-file.txt');
  return binary;
}

// After

async function someFunction() {
  const binary = await Assets.getBinaryAsync('some-file.txt');
  return binary;
}

Accounts.addEmail

它不再可用,您应该使用 Accounts.addEmailAsync

javascript
import { Accounts } from "meteor/accounts-base";

// Before

Accounts.addEmail(
  "userId",
  "newEmail",
  false,  // this param is optional 
);
// After

await Accounts.addEmailAsync(
  "userId",
  "newEmail",
  false,  // this param is optional 
);

有关更改的完整列表,请查看 Meteor v3 的变更日志