Modules
Modules allow you to separate and organize parts of your prototype across different files. They're JavaScript or CoffeeScript files, which you can include (require) within your prototype. They help you organize your code, and choose what parts to focus on.
You can find them in the /modules folder of your prototype. Modules are based on JavaScript and Node.js standards. Everything that you've prefixed with exports in your module will be available in your prototype. The require keyword imports your module.
If you want to add modules to an older project, we advice to create a new project in the latest Framer Studio, and copy over your files.
译:模块允许您单独和组织您的原型在不同的文件的部分。他们是JavaScript或我的咖啡文件,您可以包括需要在您的原型内。他们帮助您组织您的代码,选择部分重点。
你可以在你的原型的模块文件夹中找到他们。模块是基于JavaScript和节点。 js标准。所有你曾经前缀与您的模块的出口将可在您的原型。需要关键字可以将你的模块。
如果你想添加模块到一个较早的项目,我们建议创建一个新项目在最新的Framer Studio,和复制文件。
Get Started
Create a new project in Framer Studio
译:framer Studio中创建一个新项目- Navigate to the /modules folder and open the myModule.coffee file in a text-editor.
译:导航到模块文件夹,然后打开程序目录既。coffee的文本编辑器中的文件。
- Navigate to the /modules folder and open the myModule.coffee file in a text-editor.
- To include the module within your project, add the following:
译:在项目中包含模块,添加以下:
- To include the module within your project, add the following:
# To include myModule.coffee in our prototype
module = require "myModule"
Make sure to save your file and refresh your prototype to see changes. Modules can contain anything. For example, you can create Layers within your modules, or define specific interactions within functions.
译:导航到模块文件夹,然后打开程序目录既。coffee的文本编辑器中的文件。
确保保存您的文件并刷新你的原型看到变化。模块可以包含任何内容。 例如,您可以创建在您的模块内层,或定义内的特定交互功能。
# Store variables
exports.myVar = "myVariable"
# Create functions
exports.myFunction = ->
print "I'm running!"
# Create Arrays
exports.myArray = [1, 2, 3]
# Create Layers
exports.mylayerA = new Layer
backgroundColor: "#fff"
In the example above, a new layer is automatically created and included within our prototype. To also run the function, you can write:
译:上面的示例中,将自动创建一个新层,并包括在我们的原型。要运行该函数,您可以编写:
# To include myModule.coffee
module = require "myModule"
# Run the function, printing "I'm running!"
module.myFunction()