Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. let stateObject = SW.getNewStateObject();
  2.  
  3. SW.DataTypes.add("UserId", {
  4. structure: /[0-9]|[a-z]|[A-Z]/g,
  5. onValidate: (incomingValue) => {
  6. console.log(incomingValue);
  7. return true;
  8. },
  9. minLength: 1,
  10. required: true,
  11. nullable: false,
  12. defaultValue: null
  13. });
  14.  
  15. //Standard contract
  16. stateObject.defineContract("ItemsContract", {
  17. id: SW.DataTypes.use("UserId"),
  18. name: SW.DataTypes.use("String", {
  19. defaultValue: null
  20. }),
  21. age: SW.DataTypes.use("Number"),
  22. email: SW.DataTypes.use("String"),
  23. password: SW.DataTypes.use("String", {
  24. hidden: true
  25. })
  26. });
  27.  
  28. let contractItem = stateObject.createFromContract("ItemsContract", {
  29. id: String.prototype.toUniqueId(16),
  30. name: "Liviu"
  31. });
  32.  
  33. console.log(contractItem); //{id: "tqYQWvW24P5NtJum", name: "Liviu", age: null, email: null, password: null}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement