<commit_before>import resolveReference from '../resolvers/resolveReference';
import { defineProperties } from '../../utils/object';
import gatherRefs from './gatherRefs';
import { warnOnceIfDebug } from '../../utils/log';

// get relative keypaths and values
function get ( keypath ) {
	if ( !keypath ) return this._element.parentFragment.findContext().get();

	const model = resolveReference( this._element.parentFragment, keypath );

	return model ? model.get() : undefined;
}

function resolve ( path, ractive ) {
	const frag = this._element.parentFragment;

	if ( typeof path !== 'string' ) {
		return frag.findContext().getKeypath( path === undefined ? frag.ractive : path );
	}

	const model = resolveReference( frag, path );

	return model ? model.getKeypath( ractive === undefined ? frag.ractive : ractive ) : undefined;
}

// the usual mutation suspects
function add ( keypath, value ) {
	return this.ractive.add( this.resolve( keypath ), value );
}

function animate ( keypath, value, options ) {
	return this.ractive.animate( this.resolve( keypath ), value, options );
}

function pop ( keypath ) {
	return this.ractive.pop( this.resolve( keypath ) );
}

function push ( keypath, ...values ) {
	values.unshift( this.resolve( keypath ) );
	return this.ractive.push.apply( this.ractive, values );
}

function set ( keypath, value ) {
	return this.ractive.set( this.resolve( keypath ), value );
}

function shift ( keypath ) {
	return this.ractive.shift( this.resolve( keypath ) );
}

function splice ( keypath, index, drop, ...add ) {
	add.unshift( this.resolve( keypath ), index, drop );
	return this.ractive.splice.apply( this.ractive, add );
}

function subtract ( keypath, value ) {
	return this.ractive.subtract( this.resolve( keypath ), value );
}

function toggle ( keypath ) {
	return this.ractive.toggle( this.resolve( keypath ) );
}

function unshift ( keypath, ...add ) {
	add.unshift( this.resolve( keypath ) );
	return this.ractive.unshift.apply( this.ractive, add );
}

// two-way binding related helpers
function isBound () {
	const el = this._element;

	if ( el.binding ) return true;
	else return false;
}

function getBindingPath ( ractive ) {
	const el = this._element;

	if ( el.binding && el.binding.model ) return el.binding.model.getKeypath( ractive || el.parentFragment.ractive );
}

function getBinding () {
	const el = this._element;

	if ( el.binding && el.binding.model ) return el.binding.model.get();
}

function setBinding ( value ) {
	this.ractive.set( this.getBindingPath(), value );
}

// deprecated getters
function keypath () {
	warnOnceIfDebug( `Object property keypath is deprecated, please use resolve() instead.` );
	return this.resolve();
}

function rootpath () {
	warnOnceIfDebug( `Object property rootpath is deprecated, please use resolve( ractive.root ) instead.` );
	return this.resolve( this.ractive.root );<commit_msg>return promise when setting bound value from context helper<commit_after>import resolveReference from '../resolvers/resolveReference';
import { defineProperties } from '../../utils/object';
import gatherRefs from './gatherRefs';
import { warnOnceIfDebug } from '../../utils/log';

// get relative keypaths and values
function get ( keypath ) {
	if ( !keypath ) return this._element.parentFragment.findContext().get();

	const model = resolveReference( this._element.parentFragment, keypath );

	return model ? model.get() : undefined;
}

function resolve ( path, ractive ) {
	const frag = this._element.parentFragment;

	if ( typeof path !== 'string' ) {
		return frag.findContext().getKeypath( path === undefined ? frag.ractive : path );
	}

	const model = resolveReference( frag, path );

	return model ? model.getKeypath( ractive === undefined ? frag.ractive : ractive ) : undefined;
}

// the usual mutation suspects
function add ( keypath, value ) {
	return this.ractive.add( this.resolve( keypath ), value );
}

function animate ( keypath, value, options ) {
	return this.ractive.animate( this.resolve( keypath ), value, options );
}

function pop ( keypath ) {
	return this.ractive.pop( this.resolve( keypath ) );
}

function push ( keypath, ...values ) {
	values.unshift( this.resolve( keypath ) );
	return this.ractive.push.apply( this.ractive, values );
}

function set ( keypath, value ) {
	return this.ractive.set( this.resolve( keypath ), value );
}

function shift ( keypath ) {
	return this.ractive.shift( this.resolve( keypath ) );
}

function splice ( keypath, index, drop, ...add ) {
	add.unshift( this.resolve( keypath ), index, drop );
	return this.ractive.splice.apply( this.ractive, add );
}

function subtract ( keypath, value ) {
	return this.ractive.subtract( this.resolve( keypath ), value );
}

function toggle ( keypath ) {
	return this.ractive.toggle( this.resolve( keypath ) );
}

function unshift ( keypath, ...add ) {
	add.unshift( this.resolve( keypath ) );
	return this.ractive.unshift.apply( this.ractive, add );
}

// two-way binding related helpers
function isBound () {
	const el = this._element;

	if ( el.binding ) return true;
	else return false;
}

function getBindingPath ( ractive ) {
	const el = this._element;

	if ( el.binding && el.binding.model ) return el.binding.model.getKeypath( ractive || el.parentFragment.ractive );
}

function getBinding () {
	const el = this._element;

	if ( el.binding && el.binding.model ) return el.binding.model.get();
}

function setBinding ( value ) {
	return this.ractive.set( this.getBindingPath(), value );
}

// deprecated getters
function keypath () {
	warnOnceIfDebug( `Object property keypath is deprecated, please use resolve() instead.` );
	return this.resolve();
}

function rootpath () {
	warnOnceIfDebug( `Object property rootpath is deprecated, please use resolve( ractive.root ) instead.` );
	return this.resolve( this.ractive.root );
{'fraction_non_alphanumeric': 0.1367786391042205, 'fraction_numerical': 0.0, 'mean_word_length': 4.110915492957746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4606985', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1725, 'n_words': 497}