Skip to content

Releases: atsepkov/RapydScript

0.6.00

17 Oct 12:46
22c0a6a
Compare
Choose a tag to compare

Import improvements!:

  • modules do not running at load time until import foo
  • mod.thing = new_value - really changes thing inside mod
  • all module-level imports are included in module exports
  • now, it is possible:
# ------------- [ foo.pyj - some module containing async imports ] ----------------------
import bar   # normal module
async import baz #  module with deferred definition
...

# ------------- [ main.pyj - module that imports foo.pyj ] ----------------------
# before `import foo` we should define all async-modules, that `foo` depends  on 
# to do that there is a new lib - `mechanic.pyj`
import mechanic
mechanic.module_spec('baz').exports = { a_var: "baz a_var value" }

# now we can import foo
import foo
print(foo.baz.ar_var) # 'baz a_var value'

Generic AMD loader

#------------ AMD loader --------------

import mechanic
# useful:
# mechanic.module().keys() -> ['foo', 'bar', 'pack', 'pack.sub_mod' ,  ...]
# mechanic.module_spec('foo') -> {exports{}, body(), export(prop, get(), set()) }
# mechanic.module_spec().all() -> {foo: {exports{}, body(), export(prop, get(), set()) }, ...}
# mechanic.module_spec().defined() -> all().filter by if (body or exports)
# mechanic.module_spec().undefined() -> all().filter by if not (body or exports)

# ---------- [loader body]--------------
# collect all async modules from all modules/packages/submodules used in main-module (see below)
deps = mechanic.module_spec().undefined()
deps_keys = Object.keys(deps)
deps_keys_mapped = deps_keys.map(
    def(mod_name):
        map = {
                Vue: 'path/to/vue',
                axios: "path/to/axios.min",
        }
        return map[mod_name] or mod_name
)

define(deps_keys_mapped, def(*args):
    i = 0
    for dep_key in deps_keys:
       # hydrate async modules   
        mechanic.module_spec(dep_key).exports = args[i]
        i+=1

    # run main module
    import main
    # or even
    return main
)

0.5.63

20 Sep 15:11
9ee2129
Compare
Choose a tag to compare
v0.5.63

inc version