Pocket Specs
  • Welcome
  • Getting Started
    • Quickstart
    • The Why ...and Concepts
  • Usage
    • Definition File
    • Chunks
    • Patterns
  • Appendices
    • Additional Project arguments
    • Advertisements
  • Terms of Service
  • Privacy Policy
Powered by GitBook
On this page
  1. Usage

Patterns

By now, I am sure you have started understanding the innards of the workings of Pocket Specs! In this software; the word "pattern" refers to pieces of code that serve as one common logical code. It could be a function -- but it need not be. It can be just some code that one writes to achieve some activity. The file extension of such files must always be .pat.js Here is one such example. Refer the file "savenewrecord.pat.js"


const collection = $app.dao().findCollectionByNameOrId(_arg1_)
 _arg3_ = new Record(collection,_arg2_)

$app.dao().saveRecord(_arg3_)

If you examine the code above; you would see that it is for a specific type of code that is often seen in Pocketbase server side GoJa code -- which is to create a record in some collection. Another peculiarity you would have noticed that it has strange variable names such as _arg1_ and so on. Those are "tokens" which would get replaced dynamically by the variables you had specified in the 3rd argument of the instructions you gave in the chunk files. One way to understand pattern files; are to look it as a kind of "function" where _arg1_, _arg2_ etc. are the arguments you have passed on into that "function" But note; let me remind once again, the actual code need not be a JavaScript function (but can be also, if you want)

What Pocket Specs does is that it will smoothly do all those argument replacements with the variables/consts that you had asked it to use; and then integrate the completed code into the right location of your source code.

I have given a few pattern files for everyone to use. I am sure that the community of users of Pocket Specs will also contribute more pattern files for everyone to use.

PreviousChunksNextAdditional Project arguments

Last updated 8 months ago