
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Twine is a minimalistic two-way binding system.
Features:
Non-features:
Twine is available on bower via bower install twine
if that is your preference.
Twine comes as dist/twine.js
and dist/twine.min.js
in this repo and in the bower package.
Twine is also available as a gem. In your Gemfile, add gem 'twine-rails'
and include it in your application.js
manifest via //= require twine
AMD, CommonJS and Browser global (using UMD) are also supported.
Twine can be initialized simply with the following:
<script type="text/javascript">
var context = {};
$(function() {
Twine.reset(context).bind().refresh();
});
</script>
Above, context
will be considered the context root, and this will work until you navigate to a new page. On a simple app, this may be all you need to do.
Turbolinks requires a bit more consideration, as the executing JS context will remain the same -- you have the same window
object throughout operation. When the page changes and new nodes come in, they need to be re-bound manually. Twine leaves this to you, rather than attempting to guess.
Here's a sample snippet that you might use:
context = {}
document.addEventListener 'page:change', ->
Twine.reset(context).bind().refresh()
return
If you're using the jquery.turbolinks gem, then you can use:
context = {}
$ ->
Twine.reset(context).bind().refresh()
return
With TurboGraft, you may have cases where you want to keep parts of the page around, and thus, their bindings should continue to live.
The following snippet may help:
context = {}
reset = (nodes) ->
if nodes
Twine.bind(node) for node in nodes
else
Twine.reset(context).bind()
Twine.refreshImmediately()
return
document.addEventListener 'DOMContentLoaded', -> reset()
document.addEventListener 'page:load', (event) ->
reset(event.data)
return
document.addEventListener 'page:before-partial-replace', (event) ->
nodes = event.data
Twine.unbind(node) for node in nodes
return
$(document).ajaxComplete ->
Twine.refresh()
Registers a function to be called when the currently binding node and its children have finished binding.
Example:
class Foo
constructor: ->
Twine.afterBound ->
console.log("done")
# other methods needed in the context
# ...
<div context='bar' define='{bar: new Foo}'></div>
Lets you register a function to ignore certain events in order to improve performance. If the function you set returns true, then the event processing chain will be halted
Example:
Twine.shouldDiscardEvent.click = (event) ->
$target = $(event.target)
$target.hasClass('disabled')
Lets you add constructors, modules, functions, etc to Twine that are not globally available. This means you can keep your classes etc
as local variables and Twine will find them for you within define
s & eval
s.
# local_class.coffee
class LocalClass
# ...
Twine.register('LocalClass', LocalClass)
<div define="{localClass: new LocalClass()}"></div>
To get the current context in the dev console, inspect an element then type:
Twine.context($0)
Where context expects a node and $0
is shorthand for the current node in the dev console.
git clone git@github.com:Shopify/twine
cd twine
npm install
npm install -g testem coffee-script
testem
, or testem ci
package.json
, bower.json
, and lib/twine-rails/version.rb
dev up
to update Gemfile.lock
make .all && make .uglify
to update JSbundle exec rake release
npm publish
.FAQs
A minimalistic 2-way binding system
The npm package twine receives a total of 10,456 weekly downloads. As such, twine popularity was classified as popular.
We found that twine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.